处理获取不到权限的时候没有走私有文件夹的

This commit is contained in:
DESKTOP-I3JPKHK\wy 2025-11-27 16:06:02 +08:00
parent 84e518820e
commit cfe5c2fde8
2 changed files with 18 additions and 4 deletions

View File

@ -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('存储权限未授予,使用应用私有目录');

View File

@ -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<bool>(
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),