Reputation: 423
I am trying to build a background service in which I can send message from my whatsapp to the other user's whatsapp. I've tried this code
PackageManager packageManager = getApplicationContext().getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String url = "https://api.whatsapp.com/send?phone=" + "+91 7*********" + "&text=" + URLEncoder.encode("hhellow User", "UTF-8");
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
startActivity(i);
}
} catch (Exception e) {
e.printStackTrace();
}
But it is again redirecting me to whatsapp and ask me to send the message. I don't want to open my whatsapp screen, message should directly be send to the user (in background). I know this question is already asked but I didn't get my answer all are redirecting me to whatsApp.
Upvotes: 3
Views: 4236
Reputation: 2893
As per the WhatsApp FAQ there are only two ways to send text
Using Url
Using Intent
In both cases users have to click send button explicitly to send the message.
So as of now it is not possible to send message directly using any background service without clicking send button from WhatsApp itself.
Upvotes: 1