I have an app that uses android 29 sdk and has requestLegacyExternalStorage flag set to true in AndroidManifest.xml, while planning to migrate from android 10(API 29) to 11(API 30) there are few issues related to the File APIs which are used to create a directory/file in my app. I am currently using File logFile = new File(Environment.getExternalStorageDirectory() + "/xyz/logs/abc.txt");
which results in the following logcat error on running my app on android 11 device.
"file://xyz/logs/abc.txt not found"
Since Android 11 handles external Storage using https://developer.android.com/training/data-storage#scoped-storage mechanism.
Tried the following:-
adding preserveLegacyExternalStorage flag to true in androidManifext.xml results in build failure.
<application android:preserveLegacyExternalStorage='true' ></application>
. https://developer.android.com/reference/android/R.attr#preserveLegacyExternalStoragetried using MANAGE_EXTERNAL_STORAGE in manifest which strictly violates Google play policies
Is there a better way to handle this in Android 11 targeting API 30 apart from the above?