addAccountExplicitly throws IllegalStateException caused by Securityexception

左心房为你撑大大i 提交于 2019-12-01 06:59:03

问题


Using this code throws that exception and doesn't add created account into account manager.

AccountManager am = AccountManager.get(activity);
Account acc = new Account(name,activity.getString(R.string.account_type));
am.addAccountExplicitly(acc,"Password",null);

I have followed this - http://developer.android.com/training/id-auth/custom_auth.html

Any idea why it is caused?

//edit: Caused by: java.lang.SecurityException: caller uid 10035 is different than the authenticator's uid


回答1:


have you tried setting permissions in the manifest, i suspect you may need this?

<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.GET_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"></uses-permission>
<uses-permission android:name="android.permission.USE_CREDENTIALS"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>



回答2:


The documentation for AddAccountExplicitly say:

This method requires the caller to hold the permission AUTHENTICATE_ACCOUNTS and to have the same UID as the added account's authenticator.

The SecurityException that is thrown explains the problem, the UID of the application that is trying to add the account is different from the UID of the authenticator. In other words they are two different applications.

If you want these two to be separate applications you could make sure you share the UID between them. See the android:sharedUserId section of this page for a bit more information on how to do that.



来源:https://stackoverflow.com/questions/13178022/addaccountexplicitly-throws-illegalstateexception-caused-by-securityexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!