当系统中存在多个账户的时候,需要让用户手动选择或添加账户. 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 allowableAccounts allowableAccountTypes alwaysPromptForAccount descriptionOverrideText addAccountAuthTokenType addAccountRequiredFeatures addAccountOptions
if specified, indicates that the Account is the currently selected one, according to the caller's definition of selected.
an optional ArrayList of accounts that are allowed to be shown. If not specified then this field will not limit the displayed accounts.
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.
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
if non-null this string is used as the description in the accounts chooser screen rather than the default
this string is passed as the addAccount(String, String, String[], Bundle, Activity, AccountManagerCallback, Handler) authTokenType parameter
this string array is passed as the addAccount(String, String, String[], Bundle, Activity, AccountManagerCallback, Handler) requiredFeatures parameter
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);

更多相关文章

  1. Android 8.0 Tv 修改以太网ip地址 掩码 网关 DNS及DHCP和静态切
  2. Android静态注册广播receiver检测WIFI连接状况变化
  3. Android 用Shell命令设置静态ip
  4. Android下编译OpenSSL静态库
  5. 解决Android8广播的静态注册接收不到问题
  6. android: 静态XML和动态加载XML混合使用,以及重写Layout控件
  7. android平台下基于cmake编译链接ffmpeg-3.4.x的32位和64位(armea
  8. 如何有效的清除Android中无用的资源(静态代码分析)

随机推荐

  1. Cocos2d-x 3.2编译Android程序错误的解决
  2. Android实现模拟时钟(简单+漂亮)--时针、
  3. Android(安卓)Launcher 分析 .
  4. android.net.http.AndroidHttpClient And
  5. Android测试框架
  6. Android(安卓)Studio学习之对文件的基本
  7. Android的adb ||开发事项及Eclipse使用
  8. qq android 软件 测试结果
  9. google地图示例
  10. VMware 虚拟机图文安装和配置 AlmaLinux