1

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);

2 Answers2

0

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) {
}
Pang
  • 9,564
  • 146
  • 81
  • 122
faiz mir
  • 165
  • 1
  • 1
  • 10
0

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);
}
Hamza
  • 2,017
  • 1
  • 19
  • 40