How to get contacts which are used in whatsapp or other application in android

23,626

With the READ_CONTACTS permission in your manifest, you can get synced contacts given the account type. For WhatsApp it's "com.whatsapp". So:

Cursor c = getContentResolver().query(
        RawContacts.CONTENT_URI,
        new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY },
        RawContacts.ACCOUNT_TYPE + "= ?",
        new String[] { "com.whatsapp" },
        null);

ArrayList<String> myWhatsappContacts = 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.
    myWhatsappContacts.add(c.getString(contactNameColumn));
}
Share:
23,626
Vijay Rajput
Author by

Vijay Rajput

Updated on February 08, 2020

Comments

  • Vijay Rajput
    Vijay Rajput over 4 years

    Hi i want to get contact which are used by other application (like whatsapp or viber ) please see in below image

    enter image description here

    please help me about this issue thanks