Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 497
Vijay Rajput Avatar asked Jun 18 '14 03:06

Vijay Rajput


People also ask

How do you see which contacts are on WhatsApp?

WhatsApp quickly and easily recognizes which of your contacts are using WhatsApp by accessing your phone's address book. To find your favorites/contacts go to the Chats tab and tap the New chat icon. If you can't see your contacts: Make sure that your contacts are using WhatsApp.

How are applications like WhatsApp use your contact list?

In apps that use phone authentication like whatsapp: When any user opens to check his/her contacts, whatsapp will show only the contacts from your phone that are using whatsapp (like they filter your contacts).

Does WhatsApp store my contacts?

When you use contact upload and grant WhatsApp access to your device address book, WhatsApp will access and upload the phone numbers in your address book typically daily, but this depends on various factors including how often a user uses WhatsApp, including those of WhatsApp users and your other contacts.


1 Answers

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));
}
like image 186
matiash Avatar answered Sep 28 '22 05:09

matiash