处理获取不到权限的时候没有走私有文件夹的
This commit is contained in:
parent
84e518820e
commit
cfe5c2fde8
|
|
@ -282,7 +282,7 @@ class MethodChannelAppUpgradePlugin extends AppUpgradePluginPlatform {
|
||||||
debugPrint('错误: 无法获取下载路径');
|
debugPrint('错误: 无法获取下载路径');
|
||||||
throw Exception('无法获取下载路径');
|
throw Exception('无法获取下载路径');
|
||||||
}
|
}
|
||||||
debugPrint('下载路径: $savePath');
|
debugPrint('--------------------------------------------------------------------下载路径: $savePath');
|
||||||
|
|
||||||
// 下载前清理历史APK文件
|
// 下载前清理历史APK文件
|
||||||
await _clearHistoryApkFiles(savePath);
|
await _clearHistoryApkFiles(savePath);
|
||||||
|
|
@ -571,8 +571,20 @@ class MethodChannelAppUpgradePlugin extends AppUpgradePluginPlatform {
|
||||||
// 检查存储权限状态
|
// 检查存储权限状态
|
||||||
final sdkVersion = await _getAndroidSdkVersion();
|
final sdkVersion = await _getAndroidSdkVersion();
|
||||||
|
|
||||||
// Android 9 及以下需要 WRITE_EXTERNAL_STORAGE 权限来写入公共目录
|
if (sdkVersion >= 30) {
|
||||||
if (sdkVersion <= 28) {
|
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;
|
final permission = await Permission.storage.status;
|
||||||
if (!permission.isGranted) {
|
if (!permission.isGranted) {
|
||||||
debugPrint('存储权限未授予,使用应用私有目录');
|
debugPrint('存储权限未授予,使用应用私有目录');
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ class PermissionHelper {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
final proceed = await _showRationaleDialog(
|
final proceed = await _showRationaleDialog(
|
||||||
context,
|
context,
|
||||||
|
cancelText: "拒绝",
|
||||||
title: '需要文件管理权限',
|
title: '需要文件管理权限',
|
||||||
content: '为了下载更新文件到您选择的位置,我们需要访问设备存储。您也可以选择"拒绝",应用将使用私有存储空间。',
|
content: '为了下载更新文件到您选择的位置,我们需要访问设备存储。您也可以选择"拒绝",应用将使用私有存储空间。',
|
||||||
);
|
);
|
||||||
|
|
@ -300,6 +301,7 @@ class PermissionHelper {
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String title,
|
required String title,
|
||||||
required String content,
|
required String content,
|
||||||
|
String? cancelText,
|
||||||
}) async {
|
}) async {
|
||||||
final result = await showDialog<bool>(
|
final result = await showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
@ -309,7 +311,7 @@ class PermissionHelper {
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
child: const Text('取消'),
|
child: Text(cancelText ?? '取消'),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue