适配方案为:
- 添加以下权限申请:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
- 动态申请权限(需要用户手动授权):
// Android11以上需要申请所有文件访问权限
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);
}