gpt4 book ai didi

android - GET_ACCOUNT 权限未在 android N 中授予

转载 作者:行者123 更新时间:2023-11-29 02:28:05 25 4
gpt4 key购买 nike

我在做客户经理。我想检查帐户是否存在。

 private static final String TAG = "UserAccountUtil";

public static Account getAccount(Context context) {
if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "GET_ACCOUNTS not present.");

}

AccountManager accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType(Constant.ACCOUNT_TYPE);
if (accounts.length > 0) {
Log.d(TAG, "GET_ACCOUNTS present..."+accounts[0]);
return accounts[0];
} else {
Log.d(TAG, "GET_ACCOUNTS not present...");

return null;
}
}

它总是返回 null 或“GET_ACCOUNTS 不存在”。在日志中。我也在 list 中添加了。我也在请求运行时许可。

最佳答案

GET_ACCOUNTS--> Beginning with Android 6.0 (API level 23), if an app shares the signature of the authenticator that manages an account, it does not need "GET_ACCOUNTS" permission to read information about that account. On Android 5.1 and lower, all apps need "GET_ACCOUNTS" permission to read information about any account.The GET_ACCOUNTS permission is now Dead

您可以使用 READ_CONTACTS 权限代替。

  • 检查Build.VERSION.SDK_INT

演示

if (accounts.length > 0 && android.os.Build.VERSION.SDK_INT<23 ) {
Log.d(TAG, "GET_ACCOUNTS present..."+accounts[0]);
return accounts[0];
} else {
Log.d(TAG, "GET_ACCOUNTS not present...");

return null;
}

关于android - GET_ACCOUNT 权限未在 android N 中授予,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51075316/

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