我的问题是,当我从手机中获取联系人时,它会获取所有联系人(来自手机、SIM、社交帐户等)
我想知道,我是否可以单独从社交帐户获取联系人?
最佳答案
只要应用程序的联系人已同步,您就可以查询 RawContacts
(使用 list 中的 READ_CONTACTS
权限)并按帐户类型过滤它们。例如:
Cursor c = getContentResolver().query(
RawContacts.CONTENT_URI,
new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY },
RawContacts.ACCOUNT_TYPE + "= ?",
new String[] { <account type here> },
null);
ArrayList<String> myContacts = new ArrayList<String>();
int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY);
while (c.moveToNext())
{
// You can also read RawContacts.CONTACT_ID to read the
// ContactsContract.Contacts table or any of the other related ones.
myContacts.add(c.getString(contactNameColumn));
}
只需提供适当的帐户类型即可。例如:
“com.google”
用于 Gmail,“com.whatsapp”
用于 WhatsApp,“com.skype.contacts.sync”
用于 Skype,- &c.
关于android - 如何在 Android 中获取与社交媒体(谷歌、雅虎等)相关联的联系人与手机同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24408003/