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.

Note: Select outbound links may include affiliate tracking codes and AndroidGuys may receive compensation for purchases. Read our policy. As an Amazon Associate we earn from qualifying purchases.

17 COMMENTS

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

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

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

      • 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?

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

  3. 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 ?

  4. 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)));

Comments are closed.