1

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.

  • You can set the text of the message and throw an intent to open the whatsapp app for some contact, and then the user can press "Send" but you cannot send a message automatically. Is that last enough for ya? Because If It's I've a snippet to do it. – 4gus71n Nov 22 '15 at 22:00

1 Answers1

0

After a thorough examination of this issue (for my own application..), I figure out that there is no way to do it.

Nirel
  • 1,855
  • 1
  • 15
  • 26