Testing out MANAGE_EXTERNAL_STORAGE permission
I want to support MANAGE_EXTERNAL_STORAGE permission for my file manager app. I have followed the following steps to do that. I have added the following line into the manifest
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
and requested the permission on main activity using the following code:
if (Environment.isExternalStorageManager()) {
//todo when permission is granted
} else {
//request for the permission
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
My question is not regarding acquiring the permission. It is something else. When I accidentally used my old APK for Android 10 devices with legacy support for storage access, it actually worked on the Pixel 4 emulator with Android 11 in Android Studio. It asked for the write permission (WRITE_EXTERNAL_STORAGE
) while I believe that permission is no longer available on Android 11. When I went into permissions, I did not see the storage (WRITE_EXTERNAL_STORAGE
) permission (which I see on Android 6-10 devices), I saw the management (MANAGE_EXTERNAL_STORAGE
) permission for Android 11. How does this happen? Did the system map WRITE_EXTERNAL_STORAGE
into MANAGE_EXTERNAL_STORAGE
permission?
The reason I am asking is that my users who upgraded their phones from Android 10 to 11, they reported that the app (which contains the WRITE_EXTERNAL_STORAGE
only) is not responding on start. How does it work for me on my emulator with Pixel 4 Android 11? Is it possible to really get the same behavior my users get? I do not have a real Android 11 device.
Thank you.
From my own experience, starting from API 30 (android 11 and above), the below permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
is completely ignored(but MUST be included for API 29 and below in your manifest.
Having said that, users will be promoted to manually enable scoped storage on their phone settings as long as the below permission is available on your manifest.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
what you must note When targeting API 30 and above, please make sure to handle External storage gracefully else OS may denied this permission and your app may crash if try/catch is not equally implemented gracefully. Snippets below
if (Environment.isExternalStorageManager()) {
//todo when permission is granted
} else {
//request for the permission here
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
In addition, don't forget to also add android:requestLegacyExternalStorage="true"
in your manifest, this will enable your app users to opt out of scoped storage (only when your target API was 29, android 10) and your user access your app with android 11 and above.