AccountPicker

Kotlin|Java

public final classAccountPicker


Common account picker similar to the standard framework account picker introduced in ICS: newChooseAccountIntent.

Summary

Nested types

Options for building an appropriate intent to launch the Account Picker.

The builder for creating an instance of theAccountChooserOptions.

Public methods

staticIntent

Returns an intent to anActivity that prompts the user to choose from a list of accounts.

staticIntent
newChooseAccountIntent(
    @NullableAccount selectedAccount,
    @NullableArrayList<Account> allowableAccounts,
    @Nullable String[] allowableAccountTypes,
    boolean alwaysPromptForAccount,
    @NullableString descriptionOverrideText,
    @NullableString addAccountAuthTokenType,
    @Nullable String[] addAccountRequiredFeatures,
    @NullableBundle addAccountOptions
)

This method is deprecated.

usenewChooseAccountIntent

Public methods

newChooseAccountIntent

public static Intent newChooseAccountIntent(AccountPicker.AccountChooserOptions options)

Returns an intent to anActivity that prompts the user to choose from a list of accounts. The caller will then typically start the activity by calling startActivityForResult(intent, ...);.

On success the activity returns a Bundle with the account name and type specified using keysKEY_ACCOUNT_NAME andKEY_ACCOUNT_TYPE.

NOTE: for API levelO: The activity only shows accounts visible to Google Play services as opposed to newChooseAccountIntent. If chosen account has Google type it is marked as visible to the caller and will be returned bygetAccountsByType.

The most common case is to call this with one account type, e.g.:

Intent intent =    AccountPicker.newChooseAccountIntent(        new AccountChooserOptions.Builder()            .setAllowableAccountsTypes(Arrays.asList("com.google"))            .build());startActivityForResult(intent, SOME_REQUEST_CODE);
The account picker activity will return when the user has selected and/or created an account, and the resulting account name can be retrieved as follows:
protected void onActivityResult(final int requestCode, final int resultCode,        final Intent data) {    if (requestCode == SOME_REQUEST_CODE && resultCode == RESULT_OK) {        String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);  }}
Parameters
AccountPicker.AccountChooserOptions options

that controls the behavior and style of theAccountPicker.

newChooseAccountIntent

public static Intent newChooseAccountIntent(
    @NullableAccount selectedAccount,
    @NullableArrayList<Account> allowableAccounts,
    @Nullable String[] allowableAccountTypes,
    boolean alwaysPromptForAccount,
    @NullableString descriptionOverrideText,
    @NullableString addAccountAuthTokenType,
    @Nullable String[] addAccountRequiredFeatures,
    @NullableBundle addAccountOptions
)
This method is deprecated.

usenewChooseAccountIntent

Returns an intent to anActivity that prompts the user to choose from a list of accounts. The caller will then typically start the activity by calling startActivityForResult(intent, ...);.

On success the activity returns a Bundle with the account name and type specified using keysKEY_ACCOUNT_NAME andKEY_ACCOUNT_TYPE.

NOTE: for API levelO: The activity only shows accounts visible to Google Play services as opposed to newChooseAccountIntent. If chosen account has Google type it is marked as visible to the caller and will be returned bygetAccountsByType.

The most common case is to call this with one account type, e.g.:

Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[]{"com.google"},        false, null, null, null, null);startActivityForResult(intent, SOME_REQUEST_CODE);
The account picker activity will return when the user has selected and/or created an account, and the resulting account name can be retrieved as follows:
protected void onActivityResult(final int requestCode, final int resultCode,        final Intent data) {    if (requestCode == SOME_REQUEST_CODE && resultCode == RESULT_OK) {        String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);  }}
Parameters
@NullableAccount selectedAccount

if specified, indicates that theAccount is the currently selected one, according to the caller's definition of selected.

@NullableArrayList<Account> allowableAccounts

an optionalArrayList of accounts that are allowed to be shown. If not specified then this field will not limit the displayed accounts.

@Nullable String[] allowableAccountTypes

an optional string array of account types. These are used both to filter the shown accounts and to filter the list of account types that are shown when adding an account.

boolean alwaysPromptForAccount

if set, the account chooser screen is always shown, otherwise it is only shown when there is more than one account from which to choose or the calling app doesn't have theGET_ACCOUNTS permission.

@NullableString descriptionOverrideText

if non-null this string is used as the description in the accounts chooser screen rather than the default.

@NullableString addAccountAuthTokenType

this optional string is passed as theaddAccount authTokenType parameter. Current implementation does not check this value.

@Nullable String[] addAccountRequiredFeatures

this optional string array is passed as theaddAccount requiredFeatures parameter. Current implementation does not check this value.

@NullableBundle addAccountOptions

This optionalBundle is passed as theaddAccount options parameter. Can be null if sending no extra options.

Returns
Intent

anIntent that can be used to launch the ChooseAccount activity flow.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-03-17 UTC.