Member-only story

Android Sharesheet

Andres Sandoval
1 min readNov 5, 2019

--

Today I learned about “Android Sharesheet”, simply by adding one line of code to the share intent makes it look nicer.

Line of code:

Intent shareIntent = Intent.createChooser(share, null);

The below code opens the new Android Sharesheet:

/**
* Create simple share intent by simply appending the url to the {
@code shareText}.
*/
public Intent buildShareIntent(String shareText, String url) {
if (StringUtils.isEmpty(shareText) || StringUtils.isEmpty(url)) {
return null;
}

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, shareText + " " + url);
Intent shareIntent = Intent.createChooser(share, null);

return shareIntent;
}

Thanks for reading!

Google documentation:

--

--

Andres Sandoval
Andres Sandoval

Written by Andres Sandoval

I'm a passionate Android Software Engineer with over 11 years of experience. andresand.github.io/andres-about-me/ buymeacoffee.com/andresand

No responses yet