gpt4 book ai didi

android - flutter [Android] : Not able to release App with Manage External Storage Permission

转载 作者:行者123 更新时间:2023-12-04 23:39:17 27 4
gpt4 key购买 nike

我们需要允许用户将文件存储在外部存储中,同样,我们使用 MANAGE_EXTERNAL_STORAGE我们的应用程序中的许可。
理想情况下,我们使用的是 android SDK 版本 30 及更高版本 Permission.manageExternalStorage并使用 Permission.storage对于低于 30 的 android SDK 版本,如下面的代码所示

  // 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 控制台拒绝了应用程序,并拒绝了以下拒绝(我们也提交了管理存储权限的原因)。
enter image description here

最佳答案

我在我的项目中找到并应用了以下解决方案来解决上述问题。

  • 我们必须使用 SAF(Storage Access Framework)代表存储权限shared_storage这将允许我们授予共享存储中特定目录的权限,我们可以将文件存储在那里。我还在下面添加了相同的代码示例。
  •   Future<void> exportFile({
    required String csvData,
    required String fileName,
    }) async {
    Uri? selectedUriDir;
    final pref = await SharedPreferences.getInstance();
    final scopeStoragePersistUrl = pref.getString('scopeStoragePersistUrl');

    // Check User has already grant permission to any directory or not
    if (scopeStoragePersistUrl != null &&
    await isPersistedUri(Uri.parse(scopeStoragePersistUrl)) &&
    (await exists(Uri.parse(scopeStoragePersistUrl)) ?? false)) {
    selectedUriDir = Uri.parse(scopeStoragePersistUrl);
    } else {
    selectedUriDir = await openDocumentTree();
    await pref.setString('scopeStoragePersistUrl', selectedUriDir.toString());
    }
    if (selectedUriDir == null) {
    return false;
    }
    try {
    final existingFile = await findFile(selectedUriDir, fileName);
    if (existingFile != null && existingFile.isFile) {
    debugPrint("Found existing file ${existingFile.uri}");
    await delete(existingFile.uri);
    }
    final newDocumentFile = await createFileAsString(
    selectedUriDir,
    mimeType: AppConstants.csvMimeTypeWhileExport,
    content: csvData,
    displayName: fileName,
    );
    return newDocumentFile != null;
    } catch (e) {
    debugPrint("Exception while create new file: ${e.toString()}");
    return false;
    }
    }

    关于android - flutter [Android] : Not able to release App with Manage External Storage Permission,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71783148/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com