How to obtain MANAGE_EXTERNAL_STORAGE permission
Asked Answered
N

1

25

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?

Necessary answered 7/10, 2020 at 19:13 Comment(4)
That permission and the associated action only exist on API 30, none of that applies to an API 29 device. What are you trying to do?Prehuman
@Prehuman need to get access to all files.Necessary
#63842570Latakia
#62783148Patio
M
42

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);
}
Mycorrhiza answered 6/4, 2021 at 12:49 Comment(3)
what if the user returns from settings without enabling it? Do you have the request code to handle that?Dressler
Scoped storage enforcement Apps that run on Android 11 but target Android 10 (API level 29) can still request the requestLegacyExternalStorage attribute. This flag allows apps to temporarily opt out of the changes associated with scoped storage, such as granting access to different directories and different types of media files. After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag.Calabresi
this should be the accepted answer, good jobBlindfold

© 2022 - 2024 — McMap. All rights reserved.