[英]How to obtain MANAGE_EXTERNAL_STORAGE permission
I'm trying to get the MANAGE_EXTERNAL_STORAGE permission on my Android 10 (API 29) device.我正在尝试在我的 Android 10 (API 29) 设备上获得MANAGE_EXTERNAL_STORAGE权限。
https://developer.android.com/training/data-storage/manage-all-files 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?但是我怎样才能获得那个许可呢?
Android 10 doesn't require "android.permission.MANAGE_EXTERNAL_STORAGE", android:requestLegacyExternalStorage="true" under application tag in manifest will work. Android 10 不需要“android.permission.MANAGE_EXTERNAL_STORAGE”,清单中应用程序标签下的 android:requestLegacyExternalStorage="true" 将起作用。
For android 11, try this对于 android 11,试试这个
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.