Search code examples
androidandroid-intentcontactswhatsapp

Send text to specific contact programmatically (whatsapp)


I wanted to know how I can send text to a specific whatsapp contact. I found some code to view a specific contact, but not to send data.

Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
    new String[] { ContactsContract.Contacts.Data._ID }, ContactsContract.Data.DATA1 + "=?",
    new String[] { id }, null);
c.moveToFirst();
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));

startActivity(i);
c.close();

This works fine for viewing a whatsapp-contact, but how can I add some text now? Or didn't the Whatsapp-developer implement such kind of an api?


Solution

  • This is now possible through the WhatsApp Business API. Only businesses may apply to use it. This is the only way to directly send messages to phone numbers, without any human interaction.

    Sending normal messages is free. It looks like you need to host a MySQL database and the WhatsApp Business Client on your server.