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.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. Revenue generated from any potential purchases is used to fund AndroidGuys. Read our policy.