【问题标题】:Use Facebook sdk's ShareContent in share intent android在共享意图android中使用Facebook sdk的ShareContent
【发布时间】:2016-05-12 11:51:53
【问题描述】:

我正在尝试在我的应用程序中使用 shareintent,但在分享到 facebook 的链接时遇到了问题,预览中没有显示任何图像。所以尝试自定义android shareintent,以便在选择facebook时使用facebooksdk的共享功能,但我似乎无法让它工作。下面是我尝试自定义共享意图的代码,

Intent share = new Intent(android.content.Intent.ACTION_SEND);          
PackageManager pm = getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(share, 0);
for (final ResolveInfo app : activityList) {
    if (app.activityInfo.packageName.toLowerCase().startsWith("com.facebook.katana")) {
        ShareLinkContent content = new ShareLinkContent.Builder()
                            .setContentTitle(property.PropertyName)
                            .setImageUrl(Uri.parse(property.ImagePath))
                            .setContentUrl(Uri.parse(property.PropertyPermaLink))
                            .build();

        ShareDialog shareDialog = new ShareDialog(this);

        shareDialog.canShow(content);

        break;
    } else {
        share.setType("text/plain");
        share.addFlags(share.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        share.putExtra(Intent.EXTRA_SUBJECT, "");
        share.putExtra(Intent.EXTRA_TEXT, property.PropertyPermaLink);
        startActivity(Intent.createChooser(share, "Share property!"));
    }
}

调试完上面的代码后发现activitylist只包含一个元素。那么我该如何解决这个问题呢?

【问题讨论】:

  • 检查这个问题,也许它会帮助你stackoverflow.com/questions/35155890/…
  • 这仅适用于 Facebook 分享。但我想自定义我的分享意图以使用意图中所需的 Facebook 分享。

标签: android android-intent facebook-sdk-4.0


【解决方案1】:

您需要添加发送意图正在处理的 Mime 数据类型以获取返回的相应活动:

share.setType("text/plain");

【讨论】:

    【解决方案2】:

    只需尝试SharePhotoContent 而不是 ShareLinkContent。 如果您想使用 ShareLinkContent,请确保 property.ImagePath 指向真实的 http 图片链接。如果链接包含 https 检查是否在默认的 android 浏览器应用程序中运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      相关资源
      最近更新 更多