AccountPicker
public final class AccountPicker
Common account picker similar to the standard framework account picker introduced in ICS: newChooseAccountIntent.
Summary
Nested types |
|---|
public class AccountPicker.AccountChooserOptionsOptions for building an appropriate intent to launch the Account Picker. |
public class AccountPicker.AccountChooserOptions.BuilderThe builder for creating an instance of the |
Public methods |
|
|---|---|
static Intent |
Returns an intent to an |
static Intent |
This method is deprecated. |
Public methods
newChooseAccountIntent
public static Intent newChooseAccountIntent(AccountPicker.AccountChooserOptions options)
Returns an intent to an Activity 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 keys KEY_ACCOUNT_NAME and KEY_ACCOUNT_TYPE.
NOTE: for API level O: 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 by getAccountsByType.
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);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 the |
newChooseAccountIntent
public static IntentnewChooseAccountIntent(
@Nullable Account selectedAccount,
@Nullable ArrayList<Account> allowableAccounts,
@Nullable String[] allowableAccountTypes,
boolean alwaysPromptForAccount,
@Nullable String descriptionOverrideText,
@Nullable String addAccountAuthTokenType,
@Nullable String[] addAccountRequiredFeatures,
@Nullable Bundle addAccountOptions
)
Returns an intent to an Activity 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 keys KEY_ACCOUNT_NAME and KEY_ACCOUNT_TYPE.
NOTE: for API level O: 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 by getAccountsByType.
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);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 | |
|---|---|
@Nullable Account selectedAccount |
if specified, indicates that the |
@Nullable ArrayList<Account> allowableAccounts |
an optional |
@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 the |
@Nullable String descriptionOverrideText |
if non-null this string is used as the description in the accounts chooser screen rather than the default. |
@Nullable String addAccountAuthTokenType |
this optional string is passed as the |
@Nullable String[] addAccountRequiredFeatures |
this optional string array is passed as the |
@Nullable Bundle addAccountOptions |
This optional |