欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

Flutter permission_handler 权限插件的使用详解

时间:2021-06-14 09:46:59|栏目:Android代码|点击:

编译环境:Flutter 版本v1.12.hotfix9 dart SDK:2.7.2

1 pubspec.yaml中引入:

  #  权限
  permission_handler: ^3.2.0

ios中info.plist配置(根据权限情况使用):

 <!-- Permission options for the `location` group -->
 <key>NSLocationWhenInUseUsageDescription</key>
 <string>Need location when in use</string>
 <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
 <string>Always and when in use!</string>
 <key>NSLocationUsageDescription</key>
 <string>Older devices need location.</string>
 <key>NSLocationAlwaysUsageDescription</key>
 <string>Can I haz location always?</string>

 <!-- Permission options for the `mediaLibrary` group -->
 <key>NSAppleMusicUsageDescription</key>
 <string>Music!</string>
 <key>kTCCServiceMediaLibrary</key>
 <string>media</string>

 <!-- Permission options for the `calendar` group -->
 <key>NSCalendarsUsageDescription</key>
 <string>Calendars</string>

 <!-- Permission options for the `camera` group -->
 <key>NSCameraUsageDescription</key>
 <string>camera</string>

 <!-- Permission options for the `contacts` group -->
 <key>NSContactsUsageDescription</key>
 <string>contacts</string>

 <!-- Permission options for the `microphone` group -->
 <key>NSMicrophoneUsageDescription</key>
 <string>microphone</string>

 <!-- Permission options for the `speech` group -->
 <key>NSSpeechRecognitionUsageDescription</key>
 <string>speech</string>

 <!-- Permission options for the `sensors` group -->
 <key>NSMotionUsageDescription</key>
 <string>motion</string>

 <!-- Permission options for the `photos` group -->
 <key>NSPhotoLibraryUsageDescription</key>
 <string>photos</string>

 <!-- Permission options for the `reminder` group -->
 <key>NSRemindersUsageDescription</key>
 <string>reminders</string>

2 代码中具体使用:

 void chosePhoto(int index) async {
 PermissionHandler().requestPermissions(
 [PermissionGroup.photos, PermissionGroup.camera]).then((map) {
 if (map[PermissionGroup.photos] == PermissionStatus.granted ||
  map[PermissionGroup.camera] == PermissionStatus.granted) {
 chosePhotoFromPhone(context, index);
 }
 });
 }

3 总结:

在使用的过程中可能会出现androidX 或者Swift语言的适配,这时候需要根据具体情况进行修改。

上一篇:android上的一个网络接口和图片缓存框架enif简析

栏    目:Android代码

下一篇:Android listview点赞问题分析

本文标题:Flutter permission_handler 权限插件的使用详解

本文地址:http://www.codeinn.net/misctech/141816.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有