【问题标题】:SecurityException when trying to add an account尝试添加帐户时出现 SecurityException
【发布时间】:2012-04-24 14:56:48
【问题描述】:

我正在尝试使用 Android AccountManager

我有一个帐户身份验证服务,显示 UI 以输入用户名/密码。

我转到设置/帐户/添加帐户,选择我的新帐户类型,然后我会看到 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;
}

MyAccountCreatorActivityonClick 的片段

AccountManager accManager = AccountManager.get(this);
Account newAccount = new Account(email, MyAccountAuthenticator.ACCOUNT_TYPE);
accManager.setPassword(newAccount, password);

setPassword 引发异常。我已经需要所有的会计权限。我不确定是什么原因造成的。如果您需要更多代码/信息,请询问。

谢谢。

【问题讨论】:

标签: android accountmanager


【解决方案1】:

看起来很明显,但如果您的身份验证器服务尚未在 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>

【讨论】:

  • 感谢您的回答。问题没有说明我已经编写了 XML,在这种情况下存在语法故障
【解决方案2】:

感谢@imran khan,我发现我的常量值与身份验证器 XML 定义中的“完全”不匹配

【讨论】:

  • 我不明白您的“身份验证器 XML 定义”与有关 AndroidManifest 的答案有何不同。您必须匹配您的 AndroidManifest 还是其他地方的答案?
  • 如果我将 org.zighinetto.myapp.account 错误地输入为 org.zighinetto.myap.account 它将不起作用。它只是在 XML 中以一种方式定义,在代码中以另一种方式定义(公共静态最终字符串......你知道......)
【解决方案3】:

就我而言,当我在同一台设备上运行两种不同的风格时出现此错误。第二个尝试访问与第一个相同的帐户,这导致了错误。

【讨论】:

  • 我在 Android 5 手机上遇到了同样的问题,我通过更改风味维度名称解决了这个问题,感谢您的回答 :)
【解决方案4】:

在我的例子中,我不小心在 &lt;application&gt; 标签之外的 Manifest 中定义了 AuthenticatorService。将声明移到 &lt;application&gt; 中解决了这个问题。希望能帮助到别人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多