处理获取不到权限的时候没有走私有文件夹的
This commit is contained in:
parent
84e518820e
commit
cfe5c2fde8
|
|
@ -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();
|
||||
|
||||
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 权限来写入公共目录
|
||||
if (sdkVersion <= 28) {
|
||||
final permission = await Permission.storage.status;
|
||||
if (!permission.isGranted) {
|
||||
debugPrint('存储权限未授予,使用应用私有目录');
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in New Issue