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
Does this work in kitkat and above or only pre 4.4?
Yes Damien, I tried it on Kitkat and Lollipop as well as Jellybean. But didn’t try on Honeycomb or previous.
How to share Image from Android App which is coming from url to whatsapp and messenger Programmatically
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.
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?
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.
I want to send an image clicked in image view to whatsapp …how it would be semd
First save the image and then use this method to share.
Hi, can a image shows in webview can be sent. i have set of images for each product in webview can i send that.
I’ll check that and update you in a day!