java - 为什么 Accountmanager.get(context).getAccounts() 返回 securityException?

标签 java android android-permissions android-6.0-marshmallow

据我了解,Accountmanager.get(context).getAccounts 无法返回安全异常,因为它不需要权限。来自文档:

Clients of this method that have not been granted the GET_ACCOUNTS permission, will only see those accounts managed by AbstractAccountAuthenticators whose signature matches the client.

https://developer.android.com/reference/android/accounts/AccountManager.html#getAccounts()

因此,看起来好像您没有 GET_ACCOUNTS 那么没关系,但我的应用程序在调用该方法时崩溃,但出现以下异常:

caller uid # lacks any of android.permission.GET_ACCOUNTS

为什么会发生这种情况?

Account[] accounts = AccountManager.get(parentActivity).getAccounts();

最佳答案

您的应用在 list 中缺少匹配的权限。 添加

<uses-permission
     android:name="android.permission.GET_ACCOUNTS" />

到你的AndroidManifest.xml

编辑:对于 Android 6.0,在运行时请求:http://developer.android.com/training/permissions/requesting.html

GET ACCOUNTS: Allows access to the list of accounts in the Accounts Service. Protection level: dangerous

关于java - 为什么 Accountmanager.get(context).getAccounts() 返回 securityException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896837/

相关文章:

java - 基于操作系统的不同风格

android - 为什么在 Android Q 及更高版本上不需要 WRITE_EXTERNAL_STORAGE

java - Toast 项目选择 - AdapterView/ArrayList

android - ZXing.Net.Mobile 的 Xamarin.Android 相机权限仅在应用重启后有效

android - 从 android 启动服务时出现权限问题

java - 如何使用 Jackson 从 yaml 文件创建 map ?

java - 将 JScrollPane 添加到 JPopupMenu

java - 循环不起作用。找不到语义错误

java - Android - 使用查询提示使整个搜索 View 可点击

java - 如何将文件读入 Java 位图?