Search code examples
androidsettingsaccountandroid-syncadapter

Activity for Settings "Add account" option on Android


Using the SyncAdapter framework, my app is showing in the add account option in the settings menu: enter image description here

When I select "Add account" I can see my app in the list but selecting it just freezes the settings.

I guess I should tell the setting what activity to run on my app by using some intent filter but I did not find how..

Any help will be appreciated here!


Solution

  • Go to our class which extended AbstractAccountAuthenticator and override addAccount method. If addAccount method is not overrided and it is empty then the issue will be the same.

    Override the method as shown.

    @Override
    public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle bundle) throws NetworkErrorException {
    
        final Bundle result = bundle;
    
        Intent intent = new Intent(this.context, MainActivity.class);
        intent.putExtra("authtokenType", authTokenType);
        intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
        result.putParcelable(AccountManager.KEY_INTENT, intent);
    
        return result;
    }
    

    after adding this code, Go and check in the add Accounts of settings.