How to share a link to facebook without facebook app installed?

4.1k views Asked by At

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

There are 2 answers

0
mbpatel On BEST ANSWER
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);
1
mbpatel On
if (!facebookAppFound) {
  String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}