3

I wanted to know how I can send text and image to a specific whatsapp contact. I found some code to view a specific contact, but not to send data.

Uri uri = Uri.parse("smsto:" + smsNumber);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra("sms_body", smsText);  
i.setPackage("com.whatsapp");  
startActivity(i);

But that code just opening the chat history, but doesn't take the text and image and send it.

I also try the below code for send image and text via whatsApp but that ask for choose the contact for send

Intent shareIntent = new Intent();
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
    | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, sendString);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent. setPackage ("com. whatsapp");
startActivity(shareIntent);

If that functionality is possible then please give me a suggestion for this.

2

1 Answer 1

1

Solution :

        Intent sendIntent = new Intent("android.intent.action.SEND");
        File f=new File("path to the file");
        Uri uri = Uri.fromFile(f);
        sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.ContactPicker"));
        sendIntent.setType("image");
        sendIntent.putExtra(Intent.EXTRA_STREAM,uri);
        sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("919xxxxxxxxx")+"@s.whatsapp.net");
        sendIntent.putExtra(Intent.EXTRA_TEXT,"sample text you want to send along with the image");
        startActivity(sendIntent);

Refer to my answer at for detailed explanation. https://stackoverflow.com/a/41805567/3989718

2
  • for sending a text yes, the "jid" still working. But if we want to share the image, i tried but no luck.
    – gumuruh
    Aug 10, 2018 at 7:31
  • 1
    Have you found solution for this? Oct 23, 2020 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.