Reputation: 1693
In my android application after user fill textbox of mobile no and message which he wants to send to that mobile number and click send button, that message should be sent to that mobile number directly without making the user to click send button in WhatsApp app.
Below is the code I am using for sending WhatsApp message.
Uri mUri = Uri.parse("https://api.whatsapp.com/send?phone=9197xxxxxx88&text='Hello User'");
Intent intent = new Intent("android.intent.action.VIEW", mUri);
intent.setPackage("com.whatsapp");
startActivity(intent);
Upvotes: 2
Views: 5501
Reputation: 345
WhatApp is not providing any API that will do the sending part for you.
You can try with below code:
var toNumber = "+91 xxxxx xxxxx" // contains spaces.
toNumber = toNumber.replace("+", "").replace(" ", "")
val sendIntent = Intent("android.intent.action.MAIN")
sendIntent.putExtra("jid", "[email protected]")
sendIntent.putExtra(Intent.EXTRA_TEXT, "Hello")
sendIntent.action = Intent.ACTION_SEND
sendIntent.setPackage("com.whatsapp")
sendIntent.type = "text/plain"
startActivity(sendIntent)
I hope It will help you..
Upvotes: 2
Reputation: 3648
You can do that by using accessibility in android
Here you can find example like what you want Send message via whatsapp programmatically
Upvotes: 2
Reputation: 320
Below code can be used to send a predefined text to a specific number. It will open IB of that number. However, it can't automatically send for you.
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(
"https://api.whatsapp.com/send?phone=+91xxxxxxxxxx&text=Hey%20there% )));
Upvotes: 1
Reputation: 919
I believe you are looking for an What app API that will do the sending part for you.. AFAIK there is no such API exposed by Whats app for similar purpose.
Upvotes: 5