home top ad

how to share app link in android programmatically

Hi Guys. Welcome to our new instructional exercise of how to share application connect in android automatically utilizing android studio . Android utilizes the ACTION_SEND of android.content.Intent class to send information starting with one action then onto the next. To send information from outside the application to the current movement and from other action.

Typically, the ACTION_SEND action sends the URL of the build-in browser app. When sharing data, the Intent call createChooser () method that takes the Intent object and specifies the title of the selector dialog. The intent.createChooser () method allows the selector to be displayed.

  • First First Create another undertaking in Android Studio
  • File ⇒ New ⇒ Application Project
  • Then Open app -> package -> MainActivity.java and then add following code :

Java(MainActivity.java)

import android.content.Intent;   
  import android.net.Uri;   
  import android.os.Bundle;   
  import android.view.View;   
  import android.widget.Button;   
  import androidx.annotation.Nullable;   
  import androidx.appcompat.app.AppCompatActivity;   
  public class MainActivity extends AppCompatActivity {   
   private Button shareApp;   
   @Override   
   protected void onCreate(@Nullable Bundle savedInstanceState) {   
    super.onCreate(savedInstanceState);   
    setContentView(R.layout.activity_main);   
    shareApp=findViewById(R.id.share_button);   
    shareApp.setOnClickListener(new View.OnClickListener() {   
     @Override   
     public void onClick(View v) {   
     Intent shareIntent =  new Intent(android.content.Intent.ACTION_SEND);   
         shareIntent.setType("text/plain");   
         shareIntent.putExtra(Intent.EXTRA_SUBJECT,"Write what you want");   
         String app_url = " https://play.google.com/store/apps/details?id=com.example.projectname"; // Write your app package name after id  
         shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,app_url);   
         startActivity(Intent.createChooser(shareIntent, "Share with"));   
    });   
   }   
  } 
  }
Now Open res folder again layout and next again activity_main.xml and then add following code : :

  XML (activity_main.xml)

   <?xml version="1.0" encoding="utf-8"?>   
  <androidx.constraintlayout.widget.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=".MainActivity">   
   <Button   
    android:id="@+id/share_button"   
    android:layout_width="wrap_content"   
    android:layout_height="wrap_content"   
    android:text="SHARE APP"   
    app:layout_constraintBottom_toBottomOf="parent"   
    app:layout_constraintEnd_toEndOf="parent"   
    app:layout_constraintStart_toStartOf="parent"   
    app:layout_constraintTop_toTopOf="parent" />   
  </androidx.constraintlayout.widget.ConstraintLayout>  
This is also useful for you

A screen capture is given underneath with the goal that you can perceive how the work.








Now you can share the app link wherever you want, you can use this method in Navigation Drawer and Main Menu, hope that this article will be very useful for you. Thank you.Now you can share the app link wherever you want, you can use this method in Navigation Drawer and Main Menu, hope that this article will be very useful for you.

Thank you...

Post a Comment

0 Comments