Reputation: 79
My issue is, when I'm fetching contacts from phone, it will get all the contacts (from phone, SIM, social accounts etc)
i want to know, if I can get contacts from social accounts separately?
Upvotes: 7
Views: 832
Reputation: 55340
As long as the contacts for the applications are synced, you can query the RawContacts
(with the READ_CONTACTS
permission in your manifest) and get them filtered by account type. For example:
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));
}
It's just a matter of supplying the appropriate account type. For example:
"com.google"
for Gmail,"com.whatsapp"
for WhatsApp,"com.skype.contacts.sync"
for Skype,Upvotes: 1