如何在未安装Facebook应用的情况下分享链接到Facebook?

4

请查看发布至动态 - Ketan Ahir
嗨@Ketan,所以我需要实现登录按钮吗?有没有办法只实现分享按钮并检查用户是否未登录-->打开登录页面。 - hoangmeo325
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);

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

你能多说一些关于 facebookAppFound 的内容吗? - dachi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接