diff --git a/lib/app_upgrade_plugin_method_channel.dart b/lib/app_upgrade_plugin_method_channel.dart index 813f5cf..4ba217e 100644 --- a/lib/app_upgrade_plugin_method_channel.dart +++ b/lib/app_upgrade_plugin_method_channel.dart @@ -282,7 +282,7 @@ class MethodChannelAppUpgradePlugin extends AppUpgradePluginPlatform { debugPrint('错误: 无法获取下载路径'); throw Exception('无法获取下载路径'); } - debugPrint('下载路径: $savePath'); + debugPrint('--------------------------------------------------------------------下载路径: $savePath'); // 下载前清理历史APK文件 await _clearHistoryApkFiles(savePath); @@ -571,8 +571,20 @@ class MethodChannelAppUpgradePlugin extends AppUpgradePluginPlatform { // 检查存储权限状态 final sdkVersion = await _getAndroidSdkVersion(); - // Android 9 及以下需要 WRITE_EXTERNAL_STORAGE 权限来写入公共目录 - if (sdkVersion <= 28) { + if (sdkVersion >= 30) { + final manageStatus = await Permission.manageExternalStorage.status; + if (!manageStatus.isGranted) { + debugPrint('MANAGE_EXTERNAL_STORAGE 未授予,使用应用私有目录'); + return await _getAppPrivateDownloadPath(); + } + } else if (sdkVersion >= 29) { + final storageStatus = await Permission.storage.status; + if (!storageStatus.isGranted) { + debugPrint('Android 10 存储权限未授予,使用应用私有目录'); + return await _getAppPrivateDownloadPath(); + } + } else { + // Android 9 及以下需要 WRITE_EXTERNAL_STORAGE 权限来写入公共目录 final permission = await Permission.storage.status; if (!permission.isGranted) { debugPrint('存储权限未授予,使用应用私有目录'); diff --git a/lib/core/permission_helper.dart b/lib/core/permission_helper.dart index a2835d6..7d210ec 100644 --- a/lib/core/permission_helper.dart +++ b/lib/core/permission_helper.dart @@ -50,6 +50,7 @@ class PermissionHelper { if (context.mounted) { final proceed = await _showRationaleDialog( context, + cancelText: "拒绝", title: '需要文件管理权限', content: '为了下载更新文件到您选择的位置,我们需要访问设备存储。您也可以选择"拒绝",应用将使用私有存储空间。', ); @@ -300,6 +301,7 @@ class PermissionHelper { BuildContext context, { required String title, required String content, + String? cancelText, }) async { final result = await showDialog( context: context, @@ -309,7 +311,7 @@ class PermissionHelper { actions: [ TextButton( onPressed: () => Navigator.of(context).pop(false), - child: const Text('取消'), + child: Text(cancelText ?? '取消'), ), TextButton( onPressed: () => Navigator.of(context).pop(true),