適配方案為:
- 添加以下權(quán)限申請:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
- 動態(tài)申請權(quán)限(需要用戶手動授權(quán)):
// Android11以上需要申請所有文件訪問權(quán)限
boolean highPermission = Environment.isExternalStorageManager();
if (!highPermission) {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
intent.setData(Uri.fromParts("package", context.getPackageName(), null));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}