4

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

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
hoangmeo325
  • 450
  • 2
  • 10
  • 18
  • please have a look at [Publish to Feed](https://developers.facebook.com/docs/android/publish-to-feed/) – Ketan Ahir Dec 17 '13 at 06:43
  • 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 Dec 17 '13 at 09:14

2 Answers2

5
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);
mbpatel
  • 501
  • 1
  • 5
  • 19
2
if (!facebookAppFound) {
  String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
dachi
  • 1,604
  • 11
  • 15
mbpatel
  • 501
  • 1
  • 5
  • 19