我们需要允许用户将文件存储在外部存储器中,为此,在我们的应用程序中使用“MANAGE_EXTERNAL_STORAGE”权限。
理想情况下,对于Android SDK版本30及以上,我们使用“Permission.manageExternalStorage”,对于低于30的Android SDK版本,我们使用“Permission.storage”,如下所示的代码。
使用以上实现方案,在开发和内部发布过程中一切都运行良好,但是 Google Play 控制台拒绝了该应用并给出了以下拒绝原因(我们已经提交了 manage_storage 权限的原因)。
理想情况下,对于Android SDK版本30及以上,我们使用“Permission.manageExternalStorage”,对于低于30的Android SDK版本,我们使用“Permission.storage”,如下所示的代码。
// This func is added to access scope storage to export csv files
static Future<bool> externalStoragePermission(BuildContext context) async {
final androidVersion = await DeviceInfoPlugin().androidInfo;
if ((androidVersion.version.sdkInt ?? 0) >= 30) {
return await checkManageStoragePermission(context);
} else {
return await checkStoragePermission(context);
}
}
static Future<bool> checkManageStoragePermission(BuildContext context) async {
return (await Permission.manageExternalStorage.isGranted ||
await Permission.manageExternalStorage.request().isGranted);
}
static Future<bool> checkStoragePermission(BuildContext context,
{String? storageTitle, String? storageSubMessage}) async {
if (await Permission.storage.isGranted ||
await Permission.storage.request().isGranted) {
return true;
} else {
openBottomSheet(
title: storageTitle ?? Str.of(context).storagePermissionRequired,
message: storageSubMessage ?? Str.of(context).storageSubMessage,
).show(context);
return false;
}
}
使用以上实现方案,在开发和内部发布过程中一切都运行良好,但是 Google Play 控制台拒绝了该应用并给出了以下拒绝原因(我们已经提交了 manage_storage 权限的原因)。