如何在没有安装facebook应用程序的情况下分享到facebook的链接?

时间:2013-12-17 06:18:47

标签: android facebook share installed-applications

我已成功使用共享对话框与Facebook共享链接。

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

但它需要安装facebook app。那么,我如何分享facebook应用程序安装的facebook? 感谢

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:2)

if (!facebookAppFound) {
  String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}