How to add Share Option in Android App

This tutorial runs through the basic process of creating a share button, implementing the share Intent, passing your content, and building the chooser list.

Implementing the share Intent allows users of your apps to share content across multiple channels, including email, text messaging, social networking and more. You can give your users a good level of control over how they wish to share your content by letting them select from the list of sharing applications available on their own devices.

This method will contain the implementation code for sharing content from your app. You can choose to pass parameters to the method if this suits your project.

Create the sharing Intent. Add the following Java code inside your sharing method, creating an Intent object with the send action type:

This is a flexible option, as you can send plain text reliably through many different channels.

You can of course build the content using variables and methods within your application.

Pass your sharing content to the “putExtra” method of the Intent class using the following Java code:

This code passes the name of the sharing Intent along with a title to display at the top of the chooser list.

Activity_Main.Xml

MainActivity.Java

Output :-

Share

 

About Jaimin Patel

I am a Web Developer. I have been blogging and researching since 1 years and like to share my knowledge and research with the world. Peace..!!

View all posts by Jaimin Patel →

Leave a Reply

Your email address will not be published. Required fields are marked *