I'm trying to write an Android program which can identify if a given contact number is associated with WhatsApp or not. I managed to find out if a particular contact name has WhatsApp account or not. How can I find out which contact corresponding to that contact name has WhatsApp? Currently I'm using the following code:
public void identifyWhatsappContact() {
Cursor c = ctx.getContentResolver().query(
RawContacts.CONTENT_URI,
new String[] { RawContacts.CONTACT_ID, RawContacts.DISPLAY_NAME_PRIMARY },
RawContacts.ACCOUNT_TYPE + "= ? AND " + StructuredName.DISPLAY_NAME_PRIMARY + " = ?",
new String[] { "com.whatsapp", "John Doe" },
null);
ArrayList<String> myWhatsappContacts = new ArrayList<String>();
int contactNameColumn = c.getColumnIndex(RawContacts.DISPLAY_NAME_PRIMARY);
while (c.moveToNext())
{
myWhatsappContacts.add(c.getString(contactNameColumn));
Log.v("WHATSAPP", c.getString(contactNameColumn)+"");
}
}
I'm able to identify if "John Doe" has WhatsApp or not, but I can't figure out which phone number of "John Doe" has WhatsApp (assuming the contact has multiple phone numbers). Can anybody please help me? I've already tried the solution here, but it's not working for me.
This example extract all the WhatsApp numbers of a contact name: