Android中选择账户

当系统中存在多个账户的时候,需要让用户手动选择或添加账户. Android 已经提供此功能. 但因为它是AccountManager的静态方法,所以没有注意到,特此备注一下:

以下是SDK参考文档中的说明:

public static Intent newChooseAccountIntent (Account selectedAccount, ArrayList <Account > allowableAccounts, String[] allowableAccountTypes, boolean alwaysPromptForAccount, String descriptionOverrideText, String addAccountAuthTokenType, String[] addAccountRequiredFeatures, Bundle addAccountOptions)
Since: API Level 14

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 startActivityWithResult(intent, ...); .

On success the activity returns a Bundle with the account name and type specified using keys KEY_ACCOUNT_NAME and KEY_ACCOUNT_TYPE .

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

newChooseAccountsIntent(null, null, new String[]{"com.google"}, false, null,
 null, null, null);
 Parameters
selectedAccount if specified, indicates that the Account is the currently selected one, according to the caller's definition of selected.
allowableAccounts an optional ArrayList of accounts that are allowed to be shown. If not specified then this field will not limit the displayed accounts.
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.
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
descriptionOverrideText if non-null this string is used as the description in the accounts chooser screen rather than the default
addAccountAuthTokenType this string is passed as the addAccount(String, String, String[], Bundle, Activity, AccountManagerCallback, Handler) authTokenType parameter
addAccountRequiredFeatures this string array is passed as the addAccount(String, String, String[], Bundle, Activity, AccountManagerCallback, Handler) requiredFeatures parameter
addAccountOptions This Bundle is passed as the addAccount(String, String, String[], Bundle, Activity, AccountManagerCallback, Handler) options parameter
Returns
  • an Intent that can be used to launch the ChooseAccount activity flow.

代码:

                Intent intent = AccountManager.newChooseAccountIntent(
                        (Account) null, (ArrayList<Account>) null,
                        new String[] { ITRGlsAuthorizer.ACCOUNT_TYPE }, false,
                        null, ITRGlsAuthorizer.PICASA_AUTH_TOKEN_TYPE,
                        (String[]) null, (Bundle) null);
                startActivityForResult(intent, 0x20);
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值