当系统中存在多个账户的时候,需要让用户手动选择或添加账户. Android 已经提供此功能. 但因为它是AccountManager的静态方法,所以没有注意到,特此备注一下:
以下是SDK参考文档中的说明:
public
static
Intent
newChooseAccountIntent
(Account
selectedAccount, ArrayList
<Account
> allowableAccounts, String[]
allowableAccountTypes, boolean alwaysPromptForAccount, String
descriptionOverrideText, String
addAccountAuthTokenType, String[]
addAccountRequiredFeatures, 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
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);
分享到:
相关推荐
A sample app to demonstrate the use of Sync Adapters.介绍地址 http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter github上的地址:https://github.com/Udinic/SyncAdapter
简单讲述了Android上面基于账户管理的流程
删除日历的问题 日历被某账户写入了账号和事件.如何删除. 这里给出了安卓手机的通用解法. 感谢dada英语的帮助. 解决了它写入的日历无法删除的问题
国内Android登录google账户的问题
Android系统日历日程表_日历本地账户_事件_提醒的增加删除. 公司项目需要研究了几天系统的日历. 也拉出了系统内provider 下日历的数据库进行研究. 实现了添加本地账户, 基于本账户添加事件及提醒, 还有删除事件和...
Android手机谷歌账户和邮箱设置, MTK6513/6573/6575适用
Android AccountManager账户管理详解
【Android 进程保活】应用进程拉活 ( 账户同步拉活 | 账户同步 | 源码资源 ) https://hanshuliang.blog.csdn.net/article/details/115572680 博客源码快照
android AccountManager 得到指定类型的账户,显示出所有账户
Android账户管理(课程设计)源码
基于android做一个账户管理系统的app.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
【Android 进程保活】应用进程拉活 ( 账户同步拉活 | 账号服务注册 | 源码资源 ) https://hanshuliang.blog.csdn.net/article/details/115559339 博客源码快照 及 相关资源 ( 官方示例 )
android Account账户管理完整代码。开源项目代码网址:https://github.com/Udinic/AccountAuthenticator。这个不是我写的。我下载过来学习了,感觉不错。完整教材。我的博客地址:http://blog.csdn.net/qq_16064871...
基于Android的日历管理器开发源码+项目说明(提供向系统日历插入日历账户、查询日历账户、添加修改删除日历事件以及事件提醒等功能).zip 基于Android的日历管理器开发源码+项目说明(提供向系统日历插入日历账户、...
Android从2.0之后加入了账户、同步、备份框架,此次会介绍这三个框架的架构和设计,并从系统开发的角度讨论如何与Android的账户同步备份框架对接,将自己的服务集成到Android系统中。
Android自定义账户类型和同步适配器模式 Custom Account Type & SyncAdapter,博客地址:http://blog.csdn.net/w804518214/article/details/52820878
4.2.22 对话框中的进度条(ProgressDialog) 4.3 界面布局 4.3.1 垂直线性布局 4.3.2 水平线性布局 4.3.3.相对布局(RelativeLayout) 4.3.4 表单布局(TableLayout) 4.3.5 切换卡(TabWidget) 4,4 小结 第5章 Android...
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用!...基于Android的日历管理器源码+项目说明(提供向系统日历插入日历账户、查询日历账户、添加修改删除日历事件以及事件提醒等功能).zip
Android studio成品项目 点菜系统 源码 apk 可以实现登录注册功能,菜品喜欢,联系以及账户充值功能,包括源码以及apk,单机无联网功能,含项目报告。
《深入理解Android:卷2》不仅继承了第1本书的优点并改正了其在细微处存在的一些不足,而且还在写作的总体思想上进行了创新,更强调从系统设计者的角度去分析Android系统中各个模块内部的实现原理和工作机制。...