华域联盟 Andriod Flutter permission_handler 权限插件的使用详解

Flutter permission_handler 权限插件的使用详解

编译环境: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语言的适配,这时候需要根据具体情况进行修改。

到此这篇关于Flutter permission_handler 权限插件的使用的文章就介绍到这了,更多相关Flutter permission_handler 权限插件内容请搜索华域联盟以前的文章或继续浏览下面的相关文章希望大家以后多多支持华域联盟!

本文由 华域联盟 原创撰写:华域联盟 » Flutter permission_handler 权限插件的使用详解

转载请保留出处和原文链接:https://www.cnhackhy.com/108408.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

Android通过Java sdk的方式接入OpenCv的方法

Flutter 实现虎牙/斗鱼 弹幕功能

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们