6
votes

how to send a whatsapp message to a specific contact automatically?I have searched but it just opens the chat of that specific person but does not send the message automatically

Here is the code that am using:

private void openWhatsappContact(String number) {
    Uri uri = Uri.parse("smsto:" + number);
    Intent i = new Intent(Intent.ACTION_SENDTO, uri);
    i.setPackage("com.whatsapp");  
    startActivity(Intent.createChooser(i, ""));
2
To everyone downvoting, Please don't. This isn't exactly a bad question. I had similar questions when I was learning android. I had a friend who helped me out.Gautam
Did you find the solution?Ankur Raiyani

2 Answers

1
votes

I'm not sure you can send the message automatically, but try this to specify the message you want to send:

i.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");

Reference: https://www.whatsapp.com/faq/en/android/28000012

0
votes

There is no direct way to do this because whatsapp does not offer an SDK interface.

You might have some luck with writing some accessibility automations or if you have root may be some xposed module.