I found many questions about this topic, without an an answer or with broken external link. I want to add an account in a simple way. The error is always the same: java.lang.SecurityException: caller uid xxxxx is different than the authenticator's uid (where I call addAccountExplicitly). But the account type is the same in code and xml, so... where I am doing wrong?
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" />