title: How to get whatsapp Contacts from Android Programmatically?
body: <p>I have to try to get WhatsApp contacts from phone and I get a total Count of WhatsApp contact but from <code>RawContacts</code> how to get WhatsApp numbers and names that I don't know. I have tried to find a solution but can't get the exact solution for that. Please help me.</p>
  <p><strong>I put my code below.</strong></p>
  <pre><code>ContentResolver cr = context.getContentResolver();
  
  Cursor c = cr.query(
                          ContactsContract.RawContacts.CONTENT_URI,
                          new String[] { ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY },
                          ContactsContract.RawContacts.ACCOUNT_TYPE + &quot;= ?&quot;,
                          new String[] { &quot;com.whatsapp&quot; },
                          null);
  
                  ArrayList&lt;String&gt; myWhatsappContacts = new ArrayList&lt;&gt;();
  
                  String projection[] = { ContactsContract.CommonDataKinds.Phone.NUMBER };
  
                  if(c != null) {
                      if (c.getCount() &gt; 0) {
                          while (c.moveToNext()) {
  
                              String whatsappContactId = c.getString(c.getColumnIndex(ContactsContract.RawContacts.Data._ID));
  
                              Cursor dataCursor = cr.query(
                                      ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                      projection,
                                      ContactsContract.CommonDataKinds.Phone.CONTACT_ID + &quot; = ?&quot;,
                                      new String[]{whatsappContactId}, null);
                              // You can also read RawContacts.CONTACT_ID to read the
                              // ContactsContract.Contacts table or any of the other related ones.
                              String number = dataCursor.getString(dataCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NORMALIZED_NUMBER));
                              myWhatsappContacts.add(number);
  
                          }
                      }
                  }
  
                  showLogI(TAG, &quot; WhatsApp contact size :  &quot; + myWhatsappContacts.size());
  </code></pre>