Hello,
Welcome to our Microsoft Q&A platform!
Use getExternalFilesDir(), getExternalCacheDir(), or getExternalMediaDirs() (methods on Context) instead of Environment.getExternalStorageDirectory() or GetExternalStoragePublicDirectory.
Check document : https://developer.android.com/reference/android/os/Environment#getExternalStorageDirectory() .
Or, it can also be able to work with a Uri, then:
Use ACTION_CREATE_DOCUMENT to get a Uri to a location of the user's choosing, or
Use MediaStore, ContentResolver, and insert() to get a Uri for a particular type of media (e.g., an image) .
Note: Android 10 introduced a new storage paradigm for apps called scoped storage which changes the way apps store and access files on a device's external storage. If you target Android 10 (API level 29) or higher, you can opt out of these scoped storage changes on Android 10 and 11 by setting the value of android:requestLegacyExternalStorage to true in your app's manifest file. But this is not a long-term solution, as your targetSdkVersion will need to be 30 or higher .
For more details, check doc: https://developer.android.com/training/data-storage/use-cases#opt-out-scoped-storage
You can check the following hot threads to get more usefu information:
https://stackoverflow.com/questions/57116335/environment-getexternalstoragedirectory-deprecated-in-api-level-29-java
https://stackoverflow.com/questions/56468539/getexternalstoragepublicdirectory-deprecated-in-android-q
Best Regards,
Jessie Zhang
If the response is helpful, please click "Accept Answer" and upvote it.