ihimanshurawat / ImageWorker

ImageWorker is a Library for Android to Save Images in Internal Storage
55 stars 15 forks source link

Environment.getExternalStorageDirectory() is deprecated #4

Closed JanuszHain closed 3 years ago

JanuszHain commented 4 years ago

As title says, the library is using deprecated Environment.getExternalStorageDirectory()

The library in my Android 10 haven't worked. After changing to MainApp.instance.externalCacheDir (dir from context) saving and loading started working.

ihimanshurawat commented 4 years ago

Yes, you are correct Google has depreciated the Environment.getExternalStorageDirectory(). Currently, as a workaround you can opt out of these "scoped storage" changes on Android 10 and 11, if your targetSdkVersion is below 30, using android:requestLegacyExternalStorage="true" in the element of the manifest. This is not a long-term solution, as your targetSdkVersion will need to be 30 or higher sometime in 2021 if you are distributing your app through the Play Store.

ihimanshurawat commented 4 years ago

I will try to implement the fix soon. Thanks for bringing it to my attention and if you already have implement you can issue a PR.

JanuszHain commented 4 years ago

I haven't changed source code, so I can't issue a PR (sorry), but it seems like a quickfix, as class To has context, so there is only change in few lines to newer method

gyanani-ritika commented 3 years ago

https://github.com/gyanani-ritika/ContentProvider/blob/main/app/src/main/java/com/example/externalstorage/MyActivity.kt Check out my project in which I am saving a text file in phone's external storage in DOCUMENTS folder with using both, deprecated method (commented out) and MediaStore method.

skrepecki commented 3 years ago

solution ?