在 Android 10 和 11 SDK 30 中
如何访问Android设备中的所有文件并授予允许管理所有文件的权限
我已经尝试过requestLegacyExternalStorage
, defaultToDeviceProtectedStorage
, reserveLegacyExternalStorage
and MANAGE_EXTERNAL_STORAGE
许可但不工作
您可以使用下面的代码。这个对我有用。
if (SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
startActivity(new Intent(this, MainActivity.class));
} 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);
}
} else {
//below android 11=======
startActivity(new Intent(this, MainActivity.class));
ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
}
并添加行android:requestLegacyExternalStorage="true"
在清单文件中
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)