服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - Flutter permission_handler 权限插件的使用详解

Flutter permission_handler 权限插件的使用详解

2022-12-08 14:11xudailong_blog Android

这篇文章主要介绍了Flutter permission_handler 权限插件的使用,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

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

1 pubspec.yaml中引入:

  #  权限
  permission_handler: ^3.2.0

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!-- 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 代码中具体使用:

?
1
2
3
4
5
6
7
8
9
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 权限插件内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/xudailong_blog/article/details/105475462

延伸 · 阅读

精彩推荐