A Call To Action…ACTION_SEND, That Is

sendGenerally, standards are a good thing. Generally, voluntary standards are a better thing — you can choose to follow the standard for the benefits it provides or skip it if it gets in the way or you are trying to “think outside of the box”.

(as an aside, where exactly is this “box”, anyway?)

One such voluntary standard in Android is the ACTION_SEND Intent.

Let us suppose you are creating, say, an application that plays back hosted videos. Users can browse by category, search, view related videos, and play all of them back in a streaming fashion. One other thing that might be good is to “share” videos with friends.

You could do something like this:

Intent i=new Intent(android.content.Intent.ACTION_SEND);

i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, R.string.share_subject);
i.putExtra(Intent.EXTRA_TEXT, …);

startActivity(Intent.createChooser(i, R.string.share_title));

where … is replaced by some custom message with the video link and the string resources are tailored to fit your app.

What the user sees is a pop-up dialog where they can choose how to send the message. Anything configured to support the ACTION_SEND Intent in their activity will pop up. So, on a stock Android device, you might get Mail, GMail, and SMS. But, if the user has installed Twidroid, Twitter will show up as well, as Twidroid supports the ACTION_SEND protocol. Your app does not need to know anything about Twitter, or even if Twidroid happens to be installed — you just ask for the chooser, and let Android and the user take it from there.

If you are developing applications that offer a “send” or “share” or “post” or similar concept, consider supporting ACTION_SEND, perhaps in addition to anything you build into your application. That way, if the user has something installed that you do not support natively (e.g., a Facebook client), the user can still “share” via that service, without you having to do anything much in your application.

Conversely, if you are developing applications that send, share, or post, consider supporting ACTION_SEND as an Intent filter and sending messages you receive by that means. You gain by being automatically integrated into any other application that sends via ACTION_SEND and createChooser(). Moreover, there are hints that someday Android might support “find alternatives” — if the way the user wants to send is not on their device, the chooser dialog might offer an option to go search the Android Market for ACTION_SEND-supporting apps.

About author

AndroidGuys
AndroidGuys 4641 posts

Founded on November 5, 2007, we've enjoyed bringing you the latest in Android news and rumors. Updated daily, we strive to deliver reviews, opinions, and updates on all things related to Android.

You might also like

News and Rumors

TiVo App For Android Coming Soon?

All you patient Android users waiting on an official TiVo app might not have to wait much longer. According to a full-page TiVo advertisement found in the latest issue of

News and Rumors

Free trial periods come to Google Play subscriptions

Android developers will find that they have yet another tool at their disposal at it pertains to consumer satisfaction and potential revenue opportunities.  Available now, consumers can now take advantage

Deals & Steals

Deals & Discounts: Motorola Droid Maxx is $199 through Amazon for new and existing subscribers

Amazon is currently offering the Motorola DROID MAXX for $199 with a two-year service agreement. Considering that Verizon sells this guy at $299 with the same stipulation, we’re keen on

17 Comments

  1. Jason
    November 02, 14:59 Reply

    Incredible timing Mark! I was about to start looking into how to do this!
    Thanks again for your clear explanations.
    jsdf

  2. Fin
    November 02, 10:11 Reply

    ACTION SEND is a bit of a pain really if you want to do anything more than send links. I am trying to do something fairly basic (sending an email with subject, body, bcc, cc, to, small image attachment) I have tried for a literal age to get ACTION SEND to create a chooser which can provide for the full suite. No point in offering up MMS or a facebook app when it is going to discard half the things requested.

    The best thing they could do is implement a chooser which supports filtering based on attributes you want supported. Then force the consumer apps to do something consistant and sensible with the things passed to it. Something like the way you can gracefully select the most efficient location provider based on setting granularity and other requirements.

    • commonsguy
      November 03, 02:44 Reply

      ACTION_SEND is not designed for your scenario. In your case, you are trying to specify who is the recipient (BCC, CC, TO). ACTION_SEND is designed for the case where the user is asking to send something, and you know what the "something" is, but are letting the user choose the communications app and recipients.

  3. Jeff
    November 02, 17:24 Reply

    Fin, this modification will show email apps only, using it in "Here I Am" app:

    i.setType("text/xml");

  4. jsdf
    November 04, 20:56 Reply

    Mark,
    After much searching, I think you have a typo in your code.
    The MIME type listed in line 3 should be "text/plain", not "plain/text". With "plain/text", all I get is GMail. With "text/plain", I get a chooser of many options (e.g. Facebook, Twidroid, Messaging, etc.).
    Thanks,
    jsdf

    • commonsguy
      November 04, 21:56 Reply

      D'oh! Sorry about that. I have fixed the post. Thanks for pointing it out!

      • DroidDev
        November 06, 18:46 Reply

        It seems that the official facebook app only supports sending it a link, and not an arbitrary text to post as status message. Somebody know a workaround for that?

        • Graham
          November 11, 16:13 Reply

          This has been a major letdown for me. I know this is a facebook issue, they really need to respond to text better. Anyone know how to get around this? How does one actually send a link and text to facebook?!? I love ACTION_SEND and use it in my apps, but if they chose Facebook it takes them to an ugly facebook page telling them it doesn't work.

  5. droidin
    November 08, 05:25 Reply

    Oh, man! This is beyond timely!

  6. Haya
    March 30, 18:07 Reply

    what if I want to specify What the user sees in the pop-up dialog where they can choose how to send the message.

    for example I dont want peep(twitter) to apear ?

  7. Janusz
    August 06, 08:26 Reply

    Great article as always but what happened to the code formatting?

  8. Error 454
    March 23, 19:05 Reply

    Missing some getString()’s in here, should be:
    i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
    i.putExtra(Intent.EXTRA_TEXT, …);

    startActivity(Intent.createChooser(i, getString(R.string.share_title)));

Leave a Reply