How to share content in Android via ACTION_SEND

Many times android app user want to share information across several social networking sites as well as other media such as sms or text etc
User might have already installed various custom apps say FB G+ Gmail etc
Android made it easy to share the content to various apps with few lines of code
Android provides a built-in Intent called ACTION_SEND for this purpose. Using it in your app is very easy. All you have to do is to use the following couple of lines.

 Intent sharingIntent = new Intent(Intent.ACTION_SEND);
 sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("<p>This is the text that will be shared.</p>"));
 startActivity(Intent.createChooser(sharingIntent,"Share using"));

To share binary information say images video etc you need to add some additional settings say mime type etc to achieve the same

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));

Isnt it simple


What you think ? Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s