Sharing content in Android using ACTION_SEND Intent

Very often, you might want to enable the ability for users to share some content (either text, link or an image) from your Android app. Users can share the content using email, twitter, Facebook, sms or through numerous other ways.

The users might already have installed some custom apps for each one of the above service. So instead of coding all these again, it would be really nice (for both your users as well as for you as a developer) if you can invoke any one of these apps, where users want to share content from your app.

Sharing text

Android provides a built-in Intent called ACTION_SEND for this purpose. Using it in your app is very easy. All you have to do is to use the following couple of lines.

In my phone, it invokes the following dialog box listing the apps that have registered to get notification for this intent.

sharing-content-android

Sharing binary objects (Images, videos etc.)

In addition to supporting text, this intent also supports sharing images or any binary content. All you have to do is to set the appropriate mime type and then pass the binary data by calling the putExtra method.

Registering for the Intent

If you want your app to be listed when this Intent is called, then you have to add an intent filter in your manifest.xml file

android:mimeType specifies the mime type which you are interested in listening.

Happy sharing ;)

Related posts

Tags: , , ,

44 Comments so far

Follow up comments through RSS Feed | Post a comment

  • Arthur says:

    Hi,

    Thank you for this tuto, it’s very clear.

    My problem is I don’t know java…
    I’m using App Inventor to create my applications,
    as a newbie I’m struggling to find out a way to call the sharing list which is exactly what you are describing here, but it seems that no one knows (or at least shares) yet how to do it in AI (apparently with “activity starter” component but how?).

    Would it be possible for you to give us some ideas ? That would be much appreciated for us as AI users.

  • Andrew says:

    Thanks, amazing information!

  • Tom says:

    So if I wanted to sent an array of binary bytes, what would the appropriate mime type be?

  • Raghu says:

    Hi all,

    Thanks for this useful guidelines. Am new to this Android application coding. I need a small favor, actually out of those items “Facebook, Gmail, Mail, Messages and Peep”. is it possible to display only “Facebook, Gmail”. I need answer for this very much in urgent, Kindly do help me out in this. Thanks in advance

    • Sudar says:

      Raghu,

      This will list down all applications that have registered to receive that Intend. If you need only a few, then you may have to implement the entire menu yourself as part of your application.

  • vl says:

    Share your adventures, photos with Gowalla Android app.

    http://bstdownload.com/reviews/gowalla-3/

  • Shubham says:

    hi Sudar,
    thanks for sharing your knowledge.
    How can we copy and paste like functionality for Images.
    Using ClipBoard we can copy text that I know.

    pls suggest me way to do this.

    thanks lot

  • Neeraj JAiswal says:

    Hello
    I had used your app and able to launch Sharing Screen as you shown but it is not working means[Functionality].
    Like selecting Bluetooth its able to Scan Device but not getting connected.

    Any help

  • Pankaj says:

    Hi, I want show the HTML file on facebook wall and did the same as above but the share option menu showing only mail, gmail and bluetooth. It’s not showing facebook or other options.
    Note: I have included the code in menifest too.

    Thanks

    • Sudar says:

      Do you have any Facebook app installed in your phone or emulator?

      • Pankaj says:

        Yes, I have already installed facebook app for android. Thanks

        • Dhara says:

          for setType(“text/html”) facebook app is not showing in list. And if i user “text/plain” facebook twitter apps shows. But in facebook my data has not been sent and blank string will display in facebook app.
          Any help will be appreciated. I want to send message in facebook app.

  • Denis says:

    Thanks for the article.
    It turns Sharing content in Android is easy.

  • Jasmine says:

    Thanks a lot….superb code

  • Khushbu says:

    Thanks a lot for the post, but the code opens up a text editor on my device. Any suggestions on what am missing out?

  • Carol says:

    > If you want your app to be listed

    Listed?

    Listed where?

    And why would I want (or not want) this optional “listed” thing?

  • rao says:

    hi i am d learner….plz mail d code… Were i wll get this code to download……..

  • Lars Vogel says:

    @Carol: Listed in the list of applications which are displayed if an sharing intent is triggered.

  • Neeraj JAiswal says:

    Hi all,

    Thanks for this useful guidelines. Am new to this Android application coding. I need a small favor, actually out of those items “Facebook, Gmail, Mail, Messages and Peep”. is it possible to display only “Facebook, Gmail”. Kindly do help me out in this. Thanks in advance

  • dhaval says:

    i want to do when data share by intent using above code then how i receive data shared by intent. any one help me

  • dhaval says:

    how i get data shared by intent using broadcast receiver???

  • chandra says:

    hi,
    i want to create a new app,here the main thing is to share the images.
    It has the online chatting feature so whille chatting i want to share images
    to a perticular online member.Please give me some idea about this.

    Thanks in advance.

  • mike says:

    This is very useful, thanks!
    After trying this code, i was able to embed sharing, but the SMS option (Messaging) did not appear.
    What’s the trick ?

  • hello. can I do this share list in php?

  • josey baifasta says:

    you mention a possibility of sharing a link, but your example doesnt feature code explaining how to do link sharing. is it just a case of checking the “sent text” to see if it is a URL somehow or is there a specific intent filter for dealing with links/urls?

  • Kotta.Harsha says:

    Its HelpFull But I have Confuse Where I can Start.When i Click menu button show options menu in that share option select show the dialog what shown above how to integrate all in to my application please provide the step by step process for sharing image .

  • Rehan says:

    not working on facebook and linkedin,whtasapp, viber etc.
    only working in email/gmail

  • anonymous says:

    Sharing an image (binary object) only works if the image is stored on the sd card (not in getFilesDir() oder getCacheDir() directories)! Otherwise there’s an error saying “could not add image to your message” (if shared with a messaging service).

  • Anonymous says:

    hi how can i share to facebook only ?

  • suresh says:

    hii iam developing android application using phone gap. Iam struggling to add native Share in my application.. can u help me how to add ACTION_SEND code in Phone Gap?? is it possible?? thanks in advance

  • ashwani says:

    well i looking for sharing data between two devices using share intent. is it possible kindly reply ASAP

    Thanks in Advance

  • Anonymous says:

    yeeeeaaaaah

  • Please tell me how to add images that are from drawable folder to alertdialog using java… thank you sir for your support

  • Thanks for this information actually i was making an android app for New year, in that i want to share, SMS and greetings using facebook, twitter and whatsapp.. Thanks using this article i am able to do it, Actually i have made my app on App inventor. But the intent commands have helped me a lot to do what i decided with my app. :)

  • ankit says:

    i use the uri is Uri.parse(“android.resource://” + getPackageName()
    + “/drawable/” + “p1″)

  • Jayesh says:

    HI
    All things work only facebook not share the text content.

2 Tweetbacks so far

9 Trackbacks/Pingbacks so far

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>