Add “Share Image to Whatsapp” button in Android

In android we can use the default share intent to share our image to the app installed in our app(code is given below), but many times we only need specific application like whatsapp, Facebook, twitter, gmail, etc. So for that we need to do little modification in default intent for sharing.

Default sharing intent in android

    Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/jpeg");
    share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/path-to-your-image.jpg"));
    startActivity(Intent.createChooser(share, "Share Image"));

Now if we want to share this image only to any specific app like here is whatsapp, then we need to add filter that provides package name of the app. See the code below.

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/path-to-your-image.jpg"));
share.setPackage("com.whatsapp");//package name of the app
startActivity(Intent.createChooser(share, "Share Image"));

Now you can set package name of any app that can able to share image like Facebook, twitter, gmail, etc.

Download Source Code: https://github.com/dakshbhatt21/a-computer-engineer

10 thoughts on “Add “Share Image to Whatsapp” button in Android

  1. Damien February 9, 2016 / 6:05 am

    Does this work in kitkat and above or only pre 4.4?

    • dakshbhatt February 9, 2016 / 6:17 am

      Yes Damien, I tried it on Kitkat and Lollipop as well as Jellybean. But didn’t try on Honeycomb or previous.

  2. Akram November 18, 2016 / 12:21 pm

    How to share Image from Android App which is coming from url to whatsapp and messenger Programmatically

    • dakshbhatt November 20, 2016 / 10:47 am

      Hi Akram! You can first download the image from url using this: http://stackoverflow.com/a/18211171/1765573

      Then you can share it to Whatsapp by above article and for messenger, you need to change the package name of Whatsapp to messenger.

      You can just open the app with your image, you can not post it to your friend or group in Whatsapp or messenger.

  3. ANANTHARAJ GOVINDARAJ April 7, 2019 / 4:15 am

    the image share via whatsapp not sending on its own we need to click send button but i wanted to send without asking send button. How is it possible?

    • dakshbhatt May 9, 2019 / 4:53 am

      Hello Anantharaj, AFAIK I don’t think this is possible. Otherwise the other app spam whatsapp without the user consent. So user have to manually press the send button every time.

  4. mansi September 30, 2019 / 12:30 am

    I want to send an image clicked in image view to whatsapp …how it would be semd

    • dakshbhatt December 25, 2019 / 1:43 am

      First save the image and then use this method to share.

  5. Nishant Shrivastava May 18, 2020 / 2:47 am

    Hi, can a image shows in webview can be sent. i have set of images for each product in webview can i send that.

    • dakshbhatt May 18, 2020 / 3:50 am

      I’ll check that and update you in a day!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s