4

我已成功使用共享对话框共享到 facebook 的链接。

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

但它需要安装 facebook 应用程序。那么,我怎样才能分享到 facebook 哪些 facebook 应用程序安装?谢谢

4

2 回答 2

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);
于 2014-02-27T09:44:23.050 回答
2
if (!facebookAppFound) {
  String sharerUrl = "https://www.facebook.com/sharer/sharer.php?u=" + urlToShare;
  intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
于 2014-02-27T07:06:41.537 回答