当前位置: 移动技术网 > IT编程>移动开发>Android > Flutter permission_handler 权限插件的使用详解

Flutter permission_handler 权限插件的使用详解

2020年05月11日  | 移动技术网IT编程  | 我要评论

台式机网卡,我会好好的伴奏,凰图腾下载

编译环境: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 权限插件内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网