我正在尝试使用Android AccountManager
。
我有一个帐户身份验证服务,显示用于输入用户名/密码的UI。
我转到设置/帐户/添加帐户,选择我的新帐户类型,然后我看到了用户界面。
单击“确定”后,出现以下错误
04-24 14:48:29.334: E/AndroidRuntime(386): java.lang.SecurityException:
caller uid 10035 is different than the authenticator's uid
MyAccountAuthenticationService的唯一方法:
@Override
public IBinder onBind(Intent intent) {
return new MyAccountAuthenticator(this).getIBinder();
}
MyAccountAuthenticator:
@Override
public Bundle addAccount(AccountAuthenticatorResponse response,
String accountType, String authTokenType, String[] requiredFeatures,
Bundle options) throws NetworkErrorException {
final Intent intent = new Intent(context, MyAccountCreatorActivity.class);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
}
MyAccountCreatorActivity
的{{1}}
onClick
AccountManager accManager = AccountManager.get(this);
Account newAccount = new Account(email, MyAccountAuthenticator.ACCOUNT_TYPE);
accManager.setPassword(newAccount, password);
引发了异常。我已经要求所有的会计权限。我不确定是什么原因引起的。如果您需要更多代码/信息,请询问。
谢谢。
答案 0 :(得分:17)
看起来很明显,但如果您的AndroidManifest.xml中尚未定义验证器服务,您也会看到此错误。例如:
<service android:name="your.AuthService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
答案 1 :(得分:4)
感谢@imran khan,我发现我的常数值并不匹配&#34;确切地说&#34;验证者XML定义中的内容
答案 2 :(得分:3)
就我而言,当我在同一台设备上运行两种不同的风格时,我收到了这个错误。第二个是尝试访问与第一个相同的帐户,这导致了错误。
答案 3 :(得分:1)
在我的情况下,我意外地在<application>
标签之外的Manifest中定义了AuthenticatorService。在<application>
内移动声明解决了问题。希望会帮助别人。