Android - Send message to specific Whatsapp contact - android

I want to send message to specific Whatsapp contact. I have done following code but it only opens chatbox with specific contact but does not sent message.
//send message
String number="97*******";
Uri uri = Uri.parse("smsto:" + number);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Hi this is demo");
sendIntent.setPackage("com.whatsapp");
startActivity(Intent.createChooser(sendIntent, ""));
When I add
sendIntent.setType("text/plain");
it gives alert "No Application to perform this action".
Please tell how to resolve this. Thanks in advance.

Related

Send a text message for a specific number using WhatsApp

I'm trying to open WhatsApp with both text message and phone number, the phone number is OK but the message are not being displayed
Here's my code:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.SetComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.SetType("text/plain");
sendIntent.PutExtra("jid", phone_number + "#s.whatsapp.net");
sendIntent.PutExtra(Intent.ExtraText, "extra_text test");
sendIntent.PutExtra("sms_body", "sms_body test");
sendIntent.PutExtra("body", "body test");
sendIntent.PutExtra("text", "text test");
context.StartActivity(sendIntent);
I've tried all these "PutExtra" options but it's not working.
Thanks in advance!
What they allow via Intent extras is limited.
C# Example:
var sendIntent = new Intent();
sendIntent.SetPackage("com.whatsapp");
sendIntent.SetAction(Intent.ActionSend);
sendIntent.PutExtra(Intent.ExtraText, "StackOverflow.");
sendIntent.SetType("text/plain");
StartActivity(sendIntent);
Ref: https://www.whatsapp.com/faq/android/28000012

Send a text message from my android application to Whatsapp to specific Contact

I'm trying to send a text message from my android application to Whatsapp to specific Contact. when I'm using below codes, I am succeed either to send message and have to pickup contact manually, or If Specific number chat window opens, but message is blank. So is it possible to do both with one intent ? Here is my code:
I can share message to WhatsApp, but contact i have to choose manually:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.setPackage("com.whatsapp");
i.putExtra(Intent.EXTRA_TEXT, "Hello World");
try {
activity.startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
Specific number in wats app window opens, but message is blank:
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", "smsText");
i.setPackage("com.whatsapp");
activity.startActivity(i);
Below code will helps you :
String strMessageToShare=YourEditText.getText().tostring();
final Intent myIntent = new Intent(
android.content.Intent.ACTION_SEND_MULTIPLE);
myIntent.setType("text/plain");
myIntent.putExtra(android.content.Intent.EXTRA_TEXT,
new String[]{strMessageToShare});
YourActivity.this.startActivityForResult(Intent
.createChooser(myIntent, "Sharing message..."), 1);
This is what works for me.
The parameter 'body' gets not read by the whatsapp app, use 'Intent.EXTRA_TEXT' instead.
By setting the 'phoneNumber' you specify the contact to open in whatsapp.
Intent sendIntent = new Intent(Intent.ACTION_SENDTO,
Uri.parse("smsto:" + "" + phoneNumber + "?body=" + encodedMessage));
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);

Message with phone number and sms_body via whatsapp android

I have this code to send message via whatsapp
Uri uri = Uri.parse("smsto:" + PhoneNumber);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra("sms_body", "Some text");
startActivity(sendIntent);
but when whatsapp is started it filled with the phone number but not with the text provided (also i've tried with Intent.EXTRA_TEXT)

Share data with WhatsApp

I'm wondering if I can send text data from my Android application to WhatsApp without showing the contacts list of WhatsApp, I just need to set the message and the mobile number internally in my Android code?
You can try something like this:
public void sendWhatsappMessageToMsisdn(String contactNumber)
{
Uri uri = Uri.parse("smsto:" + contactNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "This is the message you want to send");
startActivity(Intent.createChooser(intent, ""));
}

This code open the correct user conversation in whatsapp but message sent in intent is missing . Why?

message = ((TextView)findViewById(R.id.message)).getText().toString().trim();
number = ((TextView)findViewById(R.id.phone)).getText().toString().trim();
Uri uri = Uri.parse("smsto:" + number);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO, uri);
//this will cause code to crash with No Activity found to handle Intent
//sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
This code open up the correct user whose phone number I typed but the EXTRA_TEXT message is not pre-populated in the whatsapp text box. What am I doing wrong ?

Categories

Resources