4
votes

I had shared link to facebook using share dialog successfully.

https://developers.facebook.com/docs/android/share-dialog/

But it requires facebook app installed. So, How can i share to facebook which out facebook application install? Thanks

2
please have a look at Publish to FeedKetan Ahir
Hi @Ketan, So I need to implement Login button? Is there any way to implement only share button and check if user is not login --> open login page.hoangmeo325

2 Answers

5
votes
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
// See if official Facebook app is found
boolean facebookAppFound = false;
List<ResolveInfo> matches = getPackageManager().queryIntentActivities(intent, 0);
for (ResolveInfo info : matches) {
if (info.activityInfo.packageName.toLowerCase().startsWith("com.facebook")) {
intent.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;  }}
// As fallback, launch sharer.php in a browser
if (!facebookAppFound) {
 String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
startActivity(intent);
2
votes
if (!facebookAppFound) {
  String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}