1
  ArrayList<String> contacts = new ArrayList<String>();

        Cursor c = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                null, null, null);
        while (c.moveToNext()) {

            String contactName = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String phNumber = c
                    .getString(c
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

            contacts.add(contactName + ":" + phNumber);

        }
        c.close();
        return contacts;

i use this code for getting mobile contacts and how to separate the whats app contacts from all mobile contacts.

mounika
  • 27
  • 10
  • http://stackoverflow.com/questions/24276573/how-to-get-contacts-which-are-used-in-whatsapp-or-other-application-in-android – ashosborne1 Nov 17 '15 at 10:53

1 Answers1

0

use this code to get all whatsapp contact and save it it array list

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
        ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
        ContactsContract.CommonDataKinds.Phone.NUMBER };
Cursor cursor = getContentResolver().query(uri, projection,
        RawContacts.ACCOUNT_TYPE + "= ?",
        new String[] { "com.whatsapp" }, null);

ArrayList<String> WContacts = new ArrayList<String>();

int indexNumber = cursor
        .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (cursor.moveToNext()) {

    WContacts.add(cursor.getString(indexNumber));
}
vishal jangid
  • 2,967
  • 16
  • 22