【发布时间】:2014-11-20 22:58:18
【问题描述】:
我发现了很多关于这个主题的问题,没有答案或外部链接损坏。我想以一种简单的方式添加一个帐户。错误总是一样的:java.lang.SecurityException: caller uid xxxxx is different than the authenticator's uid(我在这里调用 addAccountExplicitly)。但是账号类型在代码和xml中是一样的,所以……我哪里做错了?
public class AuthActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auth);
AccountManager accountManager = AccountManager.get(this);
final Account account = new Account("username", getString(R.string.account_type));
accountManager.addAccountExplicitly(account, "password", null);
}
}
<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
android:icon="@drawable/ic_launcher"
android:smallIcon="@drawable/ic_launcher"
android:label="@string/name_app" />
【问题讨论】:
-
只是为了确保您尝试添加自己的帐户类型,而不是 Google、Facebook 或类似帐户?
-
是的,我自然会尝试添加自定义类型的帐户。
标签: android account accountmanager securityexception