How to share an app on button click in Android Studio

This code get your package name of app and share it on gmail, whatsapp, facebook and all other messengers. But the important thing is to rename apk name as your package name.

Important Note!!

Your apk name must be your app package name otherwise code not work.

Example com.companyname.appname.apk

try {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
    String shareMessage = "\nLet me recommend you this application\n\n";
    shareMessage = shareMessage + "https://play.google.com/store/apps/details?id=" + getPackageName() + "\n\n";
    shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
    startActivity(Intent.createChooser(shareIntent, "choose one"));
} catch (Exception e) {
    //e.toString();
}

Leave a Reply

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