ashish pandey
ashish pandey

Reputation: 1693

Send whatsapp message directly from my android app

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. enter image description here

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

Answers (4)

Chetan Pushpad
Chetan Pushpad

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

Mahmoud Abu Alheja
Mahmoud Abu Alheja

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

DEXTOR_ANTONY
DEXTOR_ANTONY

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

Shoaeb
Shoaeb

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

Related Questions