Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain MANAGE_EXTERNAL_STORAGE permission

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?

like image 974
Serhii K. Avatar asked Oct 07 '20 19:10

Serhii K.


1 Answers

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);
}
like image 109
iamrohitsaini Avatar answered Oct 17 '22 16:10

iamrohitsaini