Wednesday 22 January 2014

Share link in facebook android example

Share link in facebook android example

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

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

String urlToShare = "http://androidtoppers.com";

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);



Screenshot:
Share link in facebook android example

2 comments:

Unknown said...

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

Unknown said...

total bullshit .................