-0.8 C
New York
Wednesday, February 21, 2024

Share Button in Android App

How to add a Share Button/ Action in Android App

This tutorial explains step by step for how to add a Share Button/ Action in Android Application via Android Studio. Share button will help share our app content.

Please follow the steps below in order to add Share Button/ Action in Android Application:

1.Go to Android studio. Remove “hello world” text and add a Button.

2.Click on the button icon and drag it to the center of the screen.

3.Click on the text tab. Change “Button” to “Share it”.

4.Go to MainActivity.java. Inside the OnClickListener, add an intent to force the application.

5.Change shareBody into shareSub.

6.Go to the live device for the explanation. You can see the button.

7.On pressing the button, you will see a pop-up screen.

8.Copy the screen to the clipboard.

9.Now click on messages.

10. Add recipients and share your subject and description.

Complete Code to Create Share Button in Android App

app > res > layout > activity_main.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schema.android.com/apk/res/android"
        android:text="SHARE IT"


app > java > com.stechies.shareData.MainActivity > MainActivity.java

package com.stechies.shareData;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity{

    Button bt;

    protected void onCreate(Bundle SavedInstanceState) {

        bt = (Button) findViewById(R.Id.button);

        bt.setOnClickListner(new View.OnClickListner () {

            protected void onClick(View v){
                Intent myIntent = new Intent(Intent.ACTION_SEND);
                String body = "Your body here";
                String sub = "Your Subject";
                startActivity(Intent.createChooser(myIntent, "Share Using"))



Related Articles

Latest Articles