Reputation: 23
Is there any intent to open chat screen for a specific whatsapp user with extra_text to be filled in edit text so user can just tap send to send message. i tried this it open chat screen for a specific user but it does not fill extra_text in edittext.
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, body);
intent.setData(Uri.parse("smsto:" + phone));
intent.setPackage("com.whatsapp");
context.startActivity(intent);
Upvotes: 1
Views: 1534
Reputation: 2045
I use this method and make sure your number not start from + your number should have country code and then number e.g. Pakistani number look like 9230812345678
private void sendWhatsAppNow(String number, String smsBody) throws Exception {
Log.d("smsActivty", "sending whats app...to" + number + "and message =" + smsBody);
Intent sendIntent = new Intent("android.intent.action.MAIN");
//sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, smsBody);
sendIntent.putExtra("jid", number + "@s.whatsapp.net"); //phone number without "+" prefix
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
Upvotes: 0
Reputation: 165
Try this.
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, path);
try {
startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
}
Upvotes: 0