Next we need to set the content-type so that the system can chose the application that can handle this content-type, in our case we need text/plain.

sharingIntent.setType("text/plain");

It’s time we set the body of our message and the subject if the application supports it:

sharingIntent.putExtra(Intent.EXTRA_TEXT, "Here the body");

Please notice that in case the user choses for example SMS or Twitter the body shouldn’t be more than 140 chars. For example if you want to send a link you should use a shorten link service. and the subject (if supoorted)

sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject here");

Now we simply need to launch our action

startActivity(Intent.createChooser(sharingIntent, "How do you want to share?"));

About The Author

I'm an electronic engineer with over 15 years of
experience in computer programming. I'm the author of the book "Android things projects". I'm a MVB at DZone and DZone Guide Author. I have contributed to the IoT guide. I'm the technical reviewer of the book Internet of Things with Arduino Blueprints(published by PacktPub). I love creating IoT projects using Arduino, Raspberry Pi,
Android, and other platforms. I am interested in the convergence
between IoT and the mobile applications. I'm SCEA, SCWCD, and SCJP
certified.
Follow on: Twitter | Linkedin

Sign up for our Newsletter

Enter your email and stay on top of things,

Get SwA updates delivered to your inbox. Article, tips, source code

×

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.