admin管理员组

文章数量:1648289

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); } } 注意,需要 android.permission.GET_ACCOUNTS权限。 运行打印的日志如下: 03-01 14:29:13.422: I/robin(32622): type:com.htc.htctwitter autohrity:com.htc.chirp.provider.Tweet 03-01 14:29:13.422: I/robin(32622): type:com.twitter.android.auth.login autohrity:com.twitter.android.provider.TwitterProvider 03-01 14:29:13.432: I/robin(32622): type:com.htc.cs autohrity:com.htc.connectedservice.csprovider 03-01 14:29:13.432: I/robin(32622): type:com.htc.android.mail.eas autohrity:htceas 03-01 14:29:13.432: I/robin(32622): type:com.htc.htctwitter autohrity:com.htc.htctwitter.Users 03-01 14:29:13.432: I/robin(32622): type: com.htc.android.Stock  autohrity: stock 03-01 14:29:13.432: I/robin(32622): type:com.htc.newsreader autohrity:com.htc.googlereader 03-01 14:29:13.432: I/robin(32622): type:com.htc.socialnetwork.facebook autohrity:com.htc.socialnetwork.facebook 03-01 14:29:13.432: I/robin(32622): type:com.htc.socialnetwork.flickr autohrity:com.htc.socialnetwork.flickr.provider.StreamProvider 03-01 14:29:13.432: I/robin(32622): type: com.google  autohrity: com.android.contacts 03-01 14:29:13.432: I/robin(32622): type:com.htc.sync.provider.weather autohrity:com.htc.sync.provider.weather 03-01 14:29:13.432: I/robin(32622): type:com.google autohrity:gmail-ls 03-01 14:29:13.432: I/robin(32622): type: com.skype.contacts.sync  autohrity: com.android.contacts 03-01 14:29:13.432: I/robin(32622): type:com.google autohrity:subscribedfeeds 03-01 14:29:13.432: I/robin(32622): type:com.htc.socialnetwork.facebook autohrity:com.android.contacts 03-01 14:29:13.432: I/robin(32622): type:com.twitter.android.auth.login autohrity:com.android.contacts 03-01 14:29:13.432: I/robin(32622): type:com.htc.android.mail autohrity:mail 03-01 14:29:13.432: I/robin(32622): type:com.htc.socialnetwork.flickr autohrity:com.android.contacts 03-01 14:29:13.432: I/robin(32622): type:com.htc.cs autohrity:com.htc.wdm.provider.WDMProvider 03-01 14:29:13.432: I/robin(32622): type:com.google autohrity:com.android.calendar 03-01 14:29:13.432: I/robin(32622): type: com.facebook.auth.login  autohrity: com.android.contacts 03-01 14:29:13.432: I/robin(32622): name: hudashi@gmail  type: com.google

本文标签: 简介Account