Share link in facebook android example

Share link in facebook android example

Here, I have written the simple code to share the link in facebook android example using the facebook application.

1. Create the link what you are going to share,

String urlToShare = "http://35.200.174.74";
2. Create the intent to share the link,
Intent intent = newIntent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);

3. Get all the available application to share the data using the ResoveInfo.

List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
4. Filter the facebook application from the group of application available to share the data.
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) {
intent.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;
}
}

5. startActivity to share the link with the Facebook,

startActivity(intent);
Download

1 thought on - Share link in facebook android example

  • if i want to share a link on a other social network, how will i do ?

Leave a Reply

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