Social-Media Link Share In Android Using Android Studio


In this article, we are going to see how to create a share button in the Android app using Android Studio. It is used to share the social links to any other sources in our mobile. This link can be provided by us.
Step 1
Create a new project in Android Studio.
Give a name to the project and click "Next".
Select the "Phone and Tablet" and click "Next".
Select an empty activity and click "Next".
At last, give the activity name and click on "Finish".
Step 2
Set up the Gradle by just locating the Gradle Scripts>>Build.Gradle
And type the following dependency in your app's build.gradle.
Code copy is here, 
  1. maven  
  2. {  
  3.    url ""  
  4. }  
Step 3
Next, go to app >> res >> layout >> activity_main.xml. Select activity page
And just type the code as follows.
Code copy is here
  1. <Button  
  2.    android:id="@+id/button"  
  3.    android:layout_width="wrap_content"  
  4.    android:layout_height="wrap_content"  
  5.    android:text="Share It"  
  6.    tools:layout_editor_absoluteX="141dp"  
  7.    tools:layout_editor_absoluteY="231dp"  
  8. />  
Step 4
Next, go to app >> java>> Select Mainactivity page,
And just type the code as follows,
Code copy is here 
  1. Button button;  
  2. @Override  
  3. protected void onCreate(Bundle savedInstanceState) {  
  4.         super.onCreate(savedInstanceState);  
  5.         setContentView(R.layout.activity_main);  
  6.         button = (Button) findViewById(;  
  7.         button.setOnClickListener(new View.OnClickListener() {  
  8.             @Override  
  9.             public void onClick(View view) {  
  10.                 Intent myIntent = new Intent(Intent.ACTION_SEND);  
  11.                 myIntent.setType("text/plain");  
  12.                 String shareBody = "Your body is here";  
  13.                 String shareSub = "Your subject";  
  14.                 myIntent.putExtra(Intent.EXTRA_SUBJECT, shareBody);  
  15.                 myIntent.putExtra(Intent.EXTRA_TEXT, shareBody);  
  16.                 startActivity(Intent.createChooser(myIntent, "Share using"));  
  17.             }  
  18.         });  
You have to provide your link in the 13th line inside sharebody.
Step 5
After step 4, Sync all the dependency gradles and resource files by clicking the Sync button on the top right corner of the Gradle page.
Step 6
Verify the preview.
->After the code is applied, the preview will appear like this.
Step 7
Next, go to Android Studio and deploy the application. Select an Emulator or your Android mobile with USB debugging enabled. Give it a few seconds to make installations and set permissions.
Run the application in your desired emulator (Shift + F10).
Explanation of source code
The source code provided in this article is just the dependencies of share option and the code used in activity_main.xml will make the button sharable and define its attributes.


In this article we created the app named Share Data, then we have inserted a Gradle and we learned how to give a share option to the button and finally, we have deployed that as an output.
*Support and Share, Thank You*

Similar Articles