0

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:-

  1. 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#preserveLegacyExternalStorage

  2. tried 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?

  • "which results in the following logcat error on running my app on android 11 device" -- I guarantee that the line you cited does not directly result in that message. Instead, you are doing something else, probably using `logFile`, that results in that message. Ideally, your [mcve] would show what you are doing with `logFile` that is triggering that message. – CommonsWare Apr 09 '21 at 11:42
  • How did you get on with this? – grolschie Nov 17 '21 at 00:02

0 Answers0