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.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(Intent.createChooser(sendIntent, "Share using"));
  • Sharing binary objects (images, videos,..)
Intent shareIntent = new Intent();
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
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:

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

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

Leave a Reply

Please Login to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.