how to share app link in android programmatically
Hello Guys. Welcome to our new tutorial of how to share app link in android programmatically using android studio. this article will help you share your google play URL link from the android app. almost every android developers use this feature to share app link. please follow the code given below to share app link in android programmatically.
- First Create a new project in Android Studio
- File ⇒ New Android ⇒ Application Project
- Then Open src -> package -> MainActivity.java and then add following code :
JAVA (MainActivity.java)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.content.Intent; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class shareactivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shareactivity); Button btn_share=(Button)findViewById(R.id.button7); btn_share.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { shareIt(); } }); } private void shareIt() { Intent intent =new Intent(); intent.setAction(Intent.ACTION_SEND); intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Android Studio Pro"); intent.putExtra(Intent.EXTRA_TEXT,"Learn Android App Development https://play.google.com/store/apps/details?id=com.tutorial.personal.androidstudiopro "); intent.setType("text/plain"); startActivity(intent); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } |
- Now Open res -> layout -> activity_main.xml and then add following code :
XML (activity_main.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".shareactivity"> <Button android:id="@+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </android.support.constraint.ConstraintLayout> |
Output:
Finally, run this project.
This is how to share link in android programmatically look like.