5

I am trying to make the users choose from a list of custom accounts of the same type using an AccountPicker.

Intent pickAccountIntent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.home.customapp"}, true, null, null, null, null);
        startActivityForResult(pickAccountIntent, 1);

I have 2 issues:

1. According to the API, if the alwaysPromptForAccount(4th parameter) is set to true the picker should be always visible.

However if there are no previous accounts of type "com.home.customapp", the picker activity is not displayed even if the alwaysPromptForAccount is set to true

How can I make the picker be always visible even if there are no custom accounts?

2. How can the add account steps be customized on order to add a custom account, not a google account?

Alex Deac
  • 69
  • 1
  • 3
  • Seeing same behavior on Android 4.4.2 with custom account type (not Google). It immediately launches the New Account Intent instead of showing the picker, regardless of that boolean parameter. – TalkLittle Jun 07 '14 at 16:46

2 Answers2

4

I just figured out that the flag only affects the case when there is exactly one account of that type. It has no effect on the case where there are zero accounts.

If there are zero accounts, regardless of the true/false value of the parameter, the picker dialog will be bypassed, and the system will immediately launch the Create Account Intent.

If there is exactly one account, and the flag is true, it will show the options to use that account or create a new account. If the flag is false, it will immediately login using the account, without giving the option to create a new account.

TalkLittle
  • 8,866
  • 6
  • 54
  • 51
0

To add an account you can use:

mAccountMgr.addAccountExplicitly(mAccount, null, null);
setAccountSync(mAccount, SOME_AUTHORITY, some_interval);

Is this what you're looking for?

Ciprian
  • 2,879
  • 3
  • 28
  • 28
  • I don't just want to add an account. I want to let the user choose from a list of existing accounts or create one if he desires to do so. – Alex Deac Dec 20 '13 at 09:09
  • then this works for me: Intent intent = AccountManager.newChooseAccountIntent(null,null, new String[] { GOOGLE_ACCOUNT_TYPE }, true, null,null, null, null); startActivityForResult(intent, ACCOUNT_CHOOSER_REQUEST_CODE); It just shows the native account picker dialog, in which the last option is create new one, of course instead of GOOGLE_ACCOUNT_TYPE you can add whatever you want – Ciprian Dec 20 '13 at 10:04