Flutter - 导致崩溃的权限问题
Flutter - permission problem causing crash
我在我的 flutter 应用程序 (https://pub.dev/packages/contacts_service) 中使用 contacts_service 包。
我也想在 Android 和 IOS 上 运行 这个应用程序,所以我将它添加到我的 Info.plist 文件中。
<key>NSContactsUsageDescription</key>
<string>This app requires contacts access to function properly.</string>
我正在我的 android 设备上开发这个应用程序,所以我还添加了权限 AndroidManifest.xml.I 在 部分上面完成了它。
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
但是应用程序在执行这行代码时崩溃了。
contacts = await ContactsService.getContacts();
错误说:
caused by: java.lang.SecurityException: Permission Denial: opening
provider com.android.providers.contacts.ContactsProvider2 from
ProcessRecord{f7cf96e 11239:com.example.smsresponder/u0a189}
(pid=11239, uid=10189) requires android.permission.READ_CONTACTS or
android.permission.WRITE_CONTACTS
此外,我注意到 Android 在我安装此应用程序时并未询问我是否获得许可。所以我假设我在授予权限方面做错了,但我不知道是什么。请帮助
您仍然需要征得用户许可才能让该应用访问设备通讯录。仅仅声明您的应用将使用这些权限是不够的。
Android >= 6 并且 iOS 要求您的应用在运行时请求敏感权限。
Note contacts_service does not handle the process of asking and
checking for permissions. To check and request user permission to
access contacts, try using the following plugins:
flutter_simple_permissions or permission_handler.
转到build.gradle
并将 targetSdkVersion 设置为 22
targetSdkVersion 22
你会没事的
我在我的 flutter 应用程序 (https://pub.dev/packages/contacts_service) 中使用 contacts_service 包。 我也想在 Android 和 IOS 上 运行 这个应用程序,所以我将它添加到我的 Info.plist 文件中。
<key>NSContactsUsageDescription</key>
<string>This app requires contacts access to function properly.</string>
我正在我的 android 设备上开发这个应用程序,所以我还添加了权限 AndroidManifest.xml.I 在
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
但是应用程序在执行这行代码时崩溃了。
contacts = await ContactsService.getContacts();
错误说:
caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{f7cf96e 11239:com.example.smsresponder/u0a189} (pid=11239, uid=10189) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
此外,我注意到 Android 在我安装此应用程序时并未询问我是否获得许可。所以我假设我在授予权限方面做错了,但我不知道是什么。请帮助
您仍然需要征得用户许可才能让该应用访问设备通讯录。仅仅声明您的应用将使用这些权限是不够的。
Android >= 6 并且 iOS 要求您的应用在运行时请求敏感权限。
Note contacts_service does not handle the process of asking and checking for permissions. To check and request user permission to access contacts, try using the following plugins: flutter_simple_permissions or permission_handler.
转到build.gradle 并将 targetSdkVersion 设置为 22
targetSdkVersion 22
你会没事的