From cfe5c2fde83394d7b046021d534eda947d74488b Mon Sep 17 00:00:00 2001 From: "DESKTOP-I3JPKHK\\wy" <1111> Date: Thu, 27 Nov 2025 16:06:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E6=9D=83=E9=99=90=E7=9A=84=E6=97=B6=E5=80=99=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=B5=B0=E7=A7=81=E6=9C=89=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app_upgrade_plugin_method_channel.dart | 18 +++++++++++++++--- lib/core/permission_helper.dart | 4 +++- 2 files changed, 18 insertions(+), 4 deletions(-) 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),