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: , ,

86 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.

  • josi yosi says:

    I think it looks like it is helpful. I thank you for that, but it has lack of details to new developers like me. Anyways, after I tried what you showed us, it worked 60%, so I had to Google in stackoverflaw and I found this that helped me solving 40% of my problems. Here is the code:

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType(“text/plain”);
    String shareBody = “This is a test”;
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, “You have to see this!”);
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);

    startActivityForResult(Intent.createChooser(sharingIntent, “Share via”),1);

    getFragmentManager().popBackStack();

    Source for the code: http://stackoverflow.com/questions/12707427/android-sharing-something-via-intent-action-send-then-automatically-return-t

  • Virat Bhavsar says:

    Viber not send image ..

    bellow is my code:
    Intent share_Intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    share_Intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
    selectedList);
    share_Intent.setType(“image/jpeg”);
    share_Intent
    .addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivity(Intent.createChooser(share_Intent,
    “Share_image_using”));

  • Virat Bhavsar says:

    its not working for viber

  • Virat Bhavsar says:

    Its not working for viber Image Sharing :

    Image not Load when we share image in viber

  • Virat Bhavsar says:

    I Solved the Problem of Viber photo sharing :

    ***********************************************************************
    Please Refer Bellow code Guys
    ***********************************************************************
    case R.id.action_Share:

    selectedList = new ArrayList();
    for (int i = 0; i < selected.size(); i++) {
    if (selected.valueAt(i)) {
    String file = mImageList.get(selected.keyAt(i));
    selectedList.add(Uri.parse("file://"+file));

    }
    }
    Intent share_Intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    share_Intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM,
    selectedList);
    share_Intent.setType("image/*");
    setResult(Activity.RESULT_OK ,share_Intent);
    share_Intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    startActivity(Intent.createChooser(share_Intent,
    "Share_image_using"));

    break;
    }

    ***********************************************************************
    put uri path like this : selectedList.add(Uri.parse("file://"+file));
    ***********************************************************************

  • android says:

    great, thanks!

  • Manish says:

    Hii,

    I am having an error sharing text,

    error log says: Are you missing a call to unragister reciever…!!!

    I am learning fresh, can anyone tell what am i missing here??

    Log Cat Says:

    “01-08 19:39:10.839: E/ActivityThread(17216): android.app.IntentReceiverLeaked: Activity com.android.internal.app.ChooserActivity has leaked IntentReceiver com.android.internal.app.ResolverActivity$1@418b4fa0 that was originally registered here. Are you missing a call to unregisterReceiver()?”

    Regards
    Manish

  • Ps says:

    Hi,

    I am not seeing facebook, messenger, whatsapp in the options when I use this code even though the apps are installed in my mobile. Any idea why this is the case?

  • Sumit says:

    Sir I want to send a 3 sec sound on intent.. How could I do it using intent.. What should I write in put extras method.. Need help.. Wat should I write in set type.

  • seven themes says:

    Thanks are very beautiful and practical

  • Karl says:

    You fail to tell which file and where in that file these pieces of code are to be placed.

  • Thanks ….. It was very good

  • Mobile click-to-call functionality is a great way to capture call data without needing a special tracking number

  • way to capture call data without needing a special tracking number

  • Moorthi says:

    Hi Sudar,
    I am trying to send an image file from one android phone to another phone using bluetooth. My requirement is to send a specified file to specified devices only. I don’t want any user interaction in between. I am using action_send intent and pls find below the code. The problem I am getting is that it is displays the list of devices and expect me to select a bluetooth device and t he specified file is transferred. I am struggling to find a solution for the last 3 weeks and any help would be much appreciated.
    code:
    File f = new File(Environment.getExternalStorageDirectory(),”test1.jpg”);

    Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
    sendIntent.setType(“image/*”);
    sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
    sendIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, device.getAddress());
    // sendIntent.setClassName(“com.android.bluetooth”, “com.broadcom.bt.app.opp.OppLauncherActivity”);

    //sendIntent.setClassName(“com.android.bluetooth”, “com.android.bluetooth.opp.BluetoothOppLauncherActivity”);
    sendIntent.setPackage(“com.android.bluetooth”);
    startActivity(sendIntent);

    and my manifest file looks:

  • ali says:

    Hi
    I want to share some let you edit text. Code share one of them I know, but I do not know what I have to share all edited text. Sharing a text editing field codes tell me.
    Thanks

  • neha says:

    plz send m the code of:

    how to share a transport app on the click of list view..

    only transport application

  • Jeroen says:

    How do you make that pop-up menu (The one in the image) come up?

  • shamsher singh says:

    Intent intent=new Intent();

    Uri screenshotUri =Uri.parse(“android.resource://com.example.pddlaptophp.freindsquits/”+ back[inm[k]]);

    //back[inm[k]] its array location store image

    intent.setAction(Intent.ACTION_SEND);
    ssintent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    ssintent.setType(“image/png”);
    startActivity(Intent.createChooser(ssintent, “share image “));

    share only massenger like whatsapp,linkdin.etc
    not share gmail,Bluetooth,facebook
    plz— help

  • khushi says:

    Hi
    I want to share a page from one user to another user of my app.Both users will get registered with my app and one of them should be able to share a page to another by using internet.I am a newbie..Please help
    Thanks

  • SRee says:

    Hi where can i find the complete code for this.

  • manikanth says:

    I want to share a contact through whatsapp, I used this code but nothing seems to work can you please help me?
    Intent i = new Intent();
    i.setType(“text/x-vcard”);
    i.setAction(Intent.ACTION_SEND);
    startActivity(Intent.createChooser(i,”Share via”));
    break;

  • m33th says:

    This way used to work for me, but not for all apps, whatsapp shows me messege “file format is not supported” is there another way?

  • Sumit kumar sah says:

    Sharing Binary objects(Images , videos etc)
    I am stuck up in “path” within Uri which path should i give.please help…

  • rakesh says:

    easily understandable

  • Suvidha Kothavade says:

    Thanks a lot….superb code

  • Deepesh says:

    Not showing Instagram app. Please help.

  • Akshay says:

    Thanks a lot….superb code

  • Meseret says:

    it is not working for me.it says “No apps can perform this action”

  • judas says:

    I need help, urgently. Just started programming in android I need to make an app that opens have the file explorer the user choose the file and share it through bluetooth that should be in the application part of the bluetooth are complicating me please someone who can help me I can send real email code who can help me please?

  • Adam Noor says:

    hello please reply me fast tell me that what path should i give to URI.parse(path) for uploading image to facebook etc. please help me

  • I need help, urgently. Just started programming in android I need to make an app that opens have the file explorer the user choose the file and share it through bluetooth that should be in the application part of the bluetooth are complicating me please someone who can help me I can send real email code who can help me please?

  • raghav soni says:

    thanks for sharing this code. I was looking for it from a long time. thanks a lot professor.

  • Devesh Kumawat says:

    Please help me to send a MMS using intent and other way.

  • William Jones says:

    Thanks

  • Very useful information discussed using well-researched facts and figures. Keep up the good work!

2 Tweetbacks so far

9 Trackbacks/Pingbacks so far

Leave a Reply

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