Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...