gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:09:48 26 4
gpt4 key购买 nike

据我了解,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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com