:
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
Log.d(TAG, account.type + "/" + account.name);
}
注意、あなたは、Android Mをターゲットにし、上記している場合、あなたは経由でこの権限をユーザーに依頼する必要がありalseます、GET_ACCOUNTS
許可が必要Runtime Permissions
モデル。で、すべての連絡先をサポートする、またはサポート・コンタクトを行うだけ(ViberのとのWhatsAppのように)読まれていないすべてのアカウントをスキップする
UPDATE
:
final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType sync : syncs) {
Log.d(TAG, "found SyncAdapter: " + sync.accountType);
if (ContactsContract.AUTHORITY.equals(sync.authority)) {
Log.d(TAG, "found SyncAdapter that supports contacts: " + sync.accountType);
if (sync.supportsUploading()) {
Log.d(TAG, "found SyncAdapter that supports contacts and is not read-only: " + sync.accountType);
// we'll now get a list of all accounts under that accountType:
Account[] accounts = AccountManager.get(this).getAccountsByType(sync.accountType);
for (Account account : accounts) {
Log.d(TAG, account.type + "/" + account.name);
}
}
}
}
を探検する自由を感じます他の良いものはSyncAdapterType
のようにisUserVisible
のようにチェックしたいかもしれません。
この方法ですべてのアカウントを取得できます。しかし、そのうちのどれを連絡先の保存に使用できますか?たとえば、私は3つのアカウント(google、whatsapp、viber)を持っていますが、実際には私はGoogleアカウント(ローカル電話機のストレージとSIMカード)でも連絡先を保存できます。 –
確かに、私の更新を参照してください – marmor
ありがとう! –