I have gone through many different threads on stackoverflow regarding this topic but havent found a solution.
Here is what I have managed to write:
Cursor c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
new String[] { ContactsContract.Contacts.Data._ID },ContactsContract.Data.DATA1 + "=?",
new String[] { "919876543210@s.whatsapp.net" }, null);
c.moveToFirst();
Intent whatsapp = new Intent(Intent.ACTION_VIEW,Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
whatsapp.putExtra(Intent.EXTRA_TEXT, "Hello !!");
if (whatsapp != null) {
context.startActivity(whatsapp);
} else {
Toast.makeText(context, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
//download for example after dialog
Uri uri = Uri.parse("market://details?id=com.whatsapp");
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
}
c.close();
The number is like this 91 - country code followed by contact number. But whenever I try this code, the whatsapp chat for that particular contact opens up. The message is not being sent.
Please help.