Просмотр исходного кода

更新安装apk前申请安装权限

gjh 1 неделя назад
Родитель
Сommit
6f8ffb3530
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      lib/dialog/app_update_dialog.dart

+ 9 - 2
lib/dialog/app_update_dialog.dart

@@ -6,11 +6,11 @@ import 'package:eitc_erm_dental_flutter/funcs.dart';
6 6
 import 'package:eitc_erm_dental_flutter/widget/custom_divider.dart';
7 7
 import 'package:eitc_erm_dental_flutter/widget/main_button.dart';
8 8
 import 'package:flutter/material.dart';
9
-import 'package:flutter/services.dart';
10 9
 import 'package:flutter_screenutil/flutter_screenutil.dart';
11 10
 import 'package:package_info_plus/package_info_plus.dart';
12 11
 import 'package:path_provider/path_provider.dart';
13 12
 import 'package:percent_indicator/percent_indicator.dart' as pi;
13
+import 'package:permission_handler/permission_handler.dart';
14 14
 
15 15
 import '../global.dart';
16 16
 import '../http/http.dart';
@@ -282,7 +282,14 @@ class _AppUpdateDialogState extends State<AppUpdateDialog> {
282 282
   }
283 283
 
284 284
   ///安装apk
285
-  void _installApk() {
285
+  void _installApk() async {
286
+    if (!await Permission.requestInstallPackages.isGranted) {
287
+      logd("app更新,没有安装apk权限,进行申请");
288
+      if (!await Permission.requestInstallPackages.request().isGranted) {
289
+        logd("app更新,申请安装apk权限被拒绝,终止安装");
290
+        return;
291
+      }
292
+    }
286 293
     logd("app更新,安装apk,path=$_filePath");
287 294
     AppInstaller.installApk(_filePath);
288 295
   }