当系统中存在多个账户的时候,需要让用户手动选择或添加账户. 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源码中的单例模式android.util.Singleton
  2. Android(安卓)8.0 Tv 修改以太网ip地址 掩码 网关 DNS及DHCP和静
  3. Android源码中的单例模式android.util.Singleton
  4. Android静态注册广播receiver检测WIFI连接状况变化
  5. Android静态注册广播receiver检测WIFI连接状况变化
  6. Android(安卓)用Shell命令设置静态ip
  7. Android下编译OpenSSL静态库
  8. android: 静态XML和动态加载XML混合使用,以及重写Layout控件
  9. 解决Android8广播的静态注册接收不到问题

随机推荐

  1. Android(安卓)android下的数据持久化和读
  2. Android应用程序请求SurfaceFlinger服务
  3. Android(安卓)在 LinearLayout 添加分割
  4. android属性详解
  5. 【EditText】Android设置EditText不可编
  6. Android快速开发架构PlanA(一),船新版本的Ba
  7. Linux/Android——input系统之 kernel层
  8. 利用Android中的SQLite进行CRUD
  9. Android属性之build.prop,及property_get/
  10. Android实现书籍翻页效果--扩展版