Android ACTION_SEND Intent

When we develop an application we want users to be able to share contents using services and applications already installed on their device such as Facebook, Twitter, SMS, Mail, etc.

This possibilities are infinite so it will be great to find a way to present to users only the applications that can share the content type required; in Android it’s available the ACTION_SEND Intent.

The use of this Intent is very simple:

  • Sharing text
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share using"));
  • Sharing binary objects (images, videos,..)
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share using"));

It’s possible to make available our application in the list of applications that Intent call to share content adding the following code inside manifest.xml:

<intent-filter> 
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="image/*" />
</intent-filter>

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

Leave a Reply

wpDiscuz