5

I want to create custom app account in settings.

Problems

  1. There is an option with icon in settings > Add account but no name
  2. When click on that(Add account), AuthenticatorActivity doesn't start. I debug Authenticator class, addAccount method is called but no activity popped.

I did the following steps:

Authenticator class(partial)

public class AccountAuthenticator extends AbstractAccountAuthenticator{
    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response,
            String accountType, String authTokenType,
            String[] requiredFeatures, Bundle options)
            throws NetworkErrorException {
        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(AccountAuthenticator.KEY_INTENT, intent);
        return bundle;
    }
}

AuthenticatorService

public class AuthenticatorService extends Service{
     @Override
    public IBinder onBind(Intent intent) {
        authenticator = new AccountAuthenticator(this);
        return authenticator.getIBinder();
    }
}

manifest

<service android:name="com.voillo.utils.AuthenticatorService" android:exported="false"
            android:label="@string/app_name">
     <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
     </intent-filter>
     <meta-data android:name="android.accounts.AccountAuthenticator"
               android:resource="@xml/authenticator" />
</service>

authenticator xml

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
     android:accountType="com.example.myapp"
     android:icon="@drawable/myapp_icon"
     android:smallIcon="@drawable/myapp_icon_small"
     android:label="myapp"
     />
shantanu
  • 2,408
  • 2
  • 26
  • 56
  • 1
    I just had a similar issue and it turned out that I had not added the authenticator activity as an activity in my manifest (facepalm). Make sure that that's not your issue. – Nathan Smith Apr 06 '15 at 17:29

2 Answers2

6

Chances are high that you forgot to declare the Activity on your Manifest File. I encountered the same error and found out that I forgot to declare my activity on the project's Manifest.

Lester
  • 283
  • 7
  • 14
0

I was fighting with this for a while, having the same issue: My AddAccount() was getting called from phone settings, but the Activity wasn't started. I managed to fix it by putting the extras in the bundle passed as an argument to the method instead of creating a new Bundle. In your case it should look something like this:

public class AccountAuthenticator extends AbstractAccountAuthenticator{
@Override
public Bundle addAccount(AccountAuthenticatorResponse response,
        String accountType, String authTokenType,
        String[] requiredFeatures, Bundle options)
        throws NetworkErrorException {
    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);

    bundle.putParcelable(AccountAuthenticator.KEY_INTENT, intent);
    return bundle;
}

And also about the Label in the XML file, you need to use a resource to get it showing in the Phone Settings.

    android:label="@string/app_name"

Hope this helps.