7

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

Vijay Rajput
  • 1,091
  • 1
  • 13
  • 18
  • Start here: http://developer.android.com/samples/BasicContactables/index.html – ditkin Jun 18 '14 at 03:39
  • hi how to find ex mobile number like 1234567890 and its used in whats app so how to find its used in whatsapp in my application contact list? – Vijay Rajput Jun 18 '14 at 03:48
  • What have tried? Are there problems with the code you are trying to get to work? – ditkin Jun 18 '14 at 03:58
  • still now not tring any code only search for that if you have any solution explain me how to do that? – Vijay Rajput Jun 18 '14 at 04:07
  • 1
    use this link http://stackoverflow.com/a/35453979/4395114 for whole description and with flow of data store table of android contacts – Mansukh Ahir Feb 17 '16 at 10:29

3 Answers3

24

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));
}
matiash
  • 54,791
  • 16
  • 125
  • 154
0

myWhatsappContacts ArrayList will contain all the phone numbers that are present in your whatsapp Application.

Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI 
                  ,new String[] {ContactsContract.Data._ID
                               ,ContactsContract.Data.DISPLAY_NAME
                               ,ContactsContract.CommonDataKinds.Phone.NUMBER 
                               ,ContactsContract.CommonDataKinds.Phone.TYPE}
                  ,ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE
                  + "' AND " + ContactsContract.RawContacts.ACCOUNT_TYPE + "= ?"
                  ,new String[] { "com.whatsapp" }
                  , null);

    while (cursor.moveToNext())
    {

        myWhatsappContacts.add(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))); 

    }
  • thanks man. that helped a'lot. (Is it also possible to send a number to whatsApp and get response if that number is on whatsapp? https://stackoverflow.com/questions/61269646/get-check-whatsapp-numbers-from-android-programmatically ) – user8462556 Apr 21 '20 at 16:03
0

System.out.print("Name : "+cursor.getString(contactNameColumn) +"\n "+" Phone Number" + cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)));

akash kumar
  • 1
  • 1
  • 1