AddAccount is not called from AbstractAccountAuthenticator implementation from MainActivity

I am following the tutorial for adding user account to Android AccountManager.

In my main activity, I have the following method:

private void addNewAccount(String accountType, String authTokenType) {
    Log.d(TAG,"addNewAccount called");
    final AccountManagerFuture<Bundle> future = mAccountManager.addAccount(accountType, authTokenType, null, null, this, new AccountManagerCallback<Bundle>() {
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                Bundle bnd = future.getResult();
                Log.d("ACME", "AddNewAccount Bundle is " + bnd);

            } catch (Exception e) {
    }, null);


This method gets called as I can see the log in logcat. Now my implementation of AbstractAccountAuthenticator looks like this:

public class AcmeAuthenticator extends AbstractAccountAuthenticator {

private String TAG = "AcmeAuthenticator";
private final Context mContext;

public AcmeAuthenticator(Context context) {
    this.mContext = context;

public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
    Log.d("acme", TAG + "> addAccount");

    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
    intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
    intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);

    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;


The above method is never called. Below is the service I created for it:

public class AcmeAuthenticatorService extends Service {
public IBinder onBind(Intent intent) {

    AcmeAuthenticator authenticator = new AcmeAuthenticator(this);
    return authenticator.getIBinder();


And my explicit definition looks like this:

<activity android:name="com.exercise.accountmanagerstudy.accountAuthenticator.AuthenticatorActivity" android:label="@string/login_label"/>
    <service android:name=".accountAuthenticator.AcmeAuthenticatorService">
            <action android:name="android.accounts.AccountAuthenticator" />
        <meta-data android:name="android.accounts.AccountAuthenticator"
            android:resource="@xml/authenticator" />
<!-- client -->
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>

<!-- Authenticator -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>


I am not getting compiler errors, the override of addAccount in the AbstractAccountAuthenticator implementation is not called. from the main addNewAccount method. I researched several links here and here . Any help would be appreciated.


source to share

1 answer

Ok, so I finally figured it out. Apparently the authenticator.xml file for AcmeAuthenticator has a field called accountType:

<?xml version="1.0" encoding="utf-8"?>


When I called addNewAccount in my main activity, I had to pass the exact value of the accountType in the above xml as the accountType argument. Ugh, it really kept me busy and I hope it helps someone else :-).



All Articles