1

When I make a call to

AccountManager.get(this).getAuthTokenByFeatures(Constants.ACCOUNT_TYPE, Constants.AUTHTOKEN_TYPE, null, this, null, null, 
                new AccountManagerCallback<Bundle>()

This is set up in my implementation for AbstractAccountAuthenticator in the overridden addAccount method

If no accounts are set up the the activity I have for adding a new account is used which is great, however if there are multiple accounts I see a list of accounts that I can choose from. I wish to customise this list via an AccountsListActivity that I have yet to create to more closely represent the Accounts & Sync option built in to the Android System.

Is it possible to set up an activity to handle what happens when a list of accounts is returned in the same way and how would I do that? I know how to write the class I just need to know how to go about getting the class called instead of a plain list of account names

If not what alternatives do I have?

jamesc
  • 12,423
  • 15
  • 74
  • 113

1 Answers1

3

I'm not quite sure if I got your question right, but if you just want to implement a possibility to select from the list of accounts you would have a few options.

Option 1

The one I went for is a simple Dialog pop-up with the accounts in it. Override the onCreateDialog in your Activity (the activity you use to obtain the accounts) like this:

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ACCOUNTS:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Title");
        final int size = accounts.length;

        String[] names = new String[size];
        for (int i = 0; i < size; i++) {
            names[i] = accounts[i].name;
        }
        builder.setItems(names, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Stuff to do when the account is selected by the user
                handleSelectedAccount(accounts[which]);
            }
        });
        return builder.create();
    }
    return null;
}

Note: accounts is the list of obtained accounts.

To display the pop-up, just call: showDialog(DIALOG_ACCOUNTS).

Option 2

Since Android 4.0, AccountManager can generate an Activity for Account selection via

Intent intent = AccountManager.newChooseAccountIntent(null, null,
                new String[] { "com.google" }, false, null, null, null,
                null);

I found this solution here: http://blog.tomtasche.at/2013/05/google-oauth-on-android-using.html

Maybe I could help you out ;)

Stefan Medack
  • 2,731
  • 26
  • 32