install android studio

How to share app on social media within the App in Android Studio

Share App :

For making the app popular in wide area , we need to share the app link on social media , so for this there is further no need to copy the link from playstore and paste it to different media one by one .

You need to just copy this code in your app project and on clicking the particular image of social icon it will automatically carry the link from your app and share on that social media .

The below codes gives the ability to share the app on Whatsapp, Facebook, Gmail, Hike etc. as shown:

Whatsapp :




public void onClickWhatsApp(View view) {
PackageManager pm = getPackageManager();
try {
Intent waIntent = new Intent("android.intent.action.SEND");
waIntent.setType("text/plain");
PackageInfo info = pm.getPackageInfo("com.whatsapp", 128);
waIntent.setPackage("com.whatsapp");
waIntent.putExtra("android.intent.extra.TEXT", "Your app link from play store");
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", 0).show();
}
}

Hike :




public void onClickhike(View view) {
PackageManager pm = getPackageManager();
try {
Intent waIntent = new Intent("android.intent.action.SEND");
waIntent.setType("text/plain");
PackageInfo info = pm.getPackageInfo("com.bsb.hike", 128);
waIntent.setPackage("com.bsb.hike");
waIntent.putExtra("android.intent.extra.TEXT", "Your app link from play store");
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "Hike not Installed", 0).show();
}
}

Facebook :




public void onClickFacebook(View view) {
String urlToShare = "https://play.google.com/store/apps/details?id=com.vision.kurukshetra.gitajayanti";
try {
Intent intent1 = new Intent();
intent1.setClassName("com.facebook.katana", "com.facebook.katana.activity.composer.ImplicitShareIntentHandler");
intent1.setAction("android.intent.action.SEND");
intent1.setType("text/plain");
intent1.putExtra("android.intent.extra.TEXT", "Your app link from play store");
startActivity(intent1);
} catch (Exception e) {
Intent intent = new Intent("android.intent.action.SEND");
startActivity(new Intent("android.intent.action.VIEW", Uri.parse("https://www.facebook.com/sharer/sharer.php?u=" + urlToShare)));
}
}

Gmail :




public void onClickgmail(View view) {
PackageManager pm = getPackageManager();
try {
Intent waIntent = new Intent("android.intent.action.SEND");
waIntent.setType("text/plain");
PackageInfo info = pm.getPackageInfo("com.gmail", 128);
waIntent.setPackage("com.gmail");
waIntent.putExtra("android.intent.extra.TEXT", "Your app link from play store");
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "Gmail not Installed", 0).show();
}
}

 

About the author

Generic Bytes

Hi! we are from Generic Bytes an aspiring bloggers with an obsession of things tech.This blog is dedicated to people who want to learn the technology.

View all posts

Leave a Reply

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