How to obtain MANAGE_EXTERNAL_STORAGE permission

Serhii K. picture Serhii K. · Oct 7, 2020 · Viewed 11.5k times · Source

I'm trying to get the MANAGE_EXTERNAL_STORAGE permission on my Android 10 (API 29) device.

https://developer.android.com/training/data-storage/manage-all-files

Manifest:

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

MainActivity:

Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
startActivity(intent);

The result is:

No Activity found to handle Intent { act=android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION }

Okay, this behaviour is possible. The doc says:

In some cases, a matching Activity may not exist, so ensure you safeguard against this.

But how can I obtain that permission?

Answer

iamrohitsaini picture iamrohitsaini · Apr 6, 2021

Android 10 doesn't require "android.permission.MANAGE_EXTERNAL_STORAGE", android:requestLegacyExternalStorage="true" under application tag in manifest will work.

For android 11, try this

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);
}