Account简介

android中的android.accounts.Account代表的是手机的基本账号信息(name和type).

我们可以通过AccountManager取得Android手机的所有账号。
比如:
AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccounts();
然而每种 type 的Account支持的 AUTHORITY (比如 ContactsContract.AUTHORITY )并不尽相同。
我们可以通过 ContentResolver.getSyncAdapterTypes() 取得的 SyncAdapterType 来查询每种 type 的Account支持那些 AUTHORITY
示例程序
void   listAccount () {
Context context=HelloActivity.this;
AccountManager am = AccountManager.get(context);
Account[] accounts = am.getAccounts();
HashSet<String> contactAccountTypes = new HashSet<String>();
SyncAdapterType []  syncs  =  ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType sync : syncs) {
Log.i(tag,"type:"+sync.accountType+" autohrity:"+sync.authority);
if (ContactsContract.AUTHORITY.equals(sync.authority)
&& sync.supportsUploading()) {
contactAccountTypes.add(sync.accountType);
}
}
ArrayList<Account> contactAccounts = new ArrayList<Account>();
for (Account acct : accounts) {
if (contactAccountTypes.contains(acct.type)) {
contactAccounts.add(acct);
}
}
 
for (Account ac : contactAccounts) {
Log.i(tag, "name:" + ac.name + " type:" + ac.type);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值