【问题标题】:Share a link from Android App using facebook-android-sdk with local image使用 facebook-android-sdk 与本地图像共享来自 Android 应用程序的链接
【发布时间】:2016-08-03 03:05:32
【问题描述】:

我的 android 应用程序使用 facebook-android-sdk:4.14.0 来分享链接。我使用 ShareLinkContent 创建共享内容并调用 setImageUrl() 来指定图像。我想使用我的应用程序中的图像(而不是来自 Internet url 链接)在共享帖子上显示。我已经尝试过以下代码,但它不起作用:

if (ShareDialog.canShow(ShareLinkContent.class)) {
    ShareLinkContent linkContent = new ShareLinkContent.Builder()
            .setContentTitle("...")
            .setContentDescription("...")
            .setContentUrl(Uri.parse("https://...))
            .setImageUrl(Uri.parse("file:///android_asset/ic_boxworldpro.png"))
            .build();

    shareDialog.show(linkContent);
} else {
    Toast.makeText(MainMenuActivity.this, "Unable to Share...Try again.",
            Toast.LENGTH_SHORT).show();
}

我也尝试使用可绘制的图像,但现象相同

.setImageUrl(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.ic_boxworldpro))

谁能帮帮我!!

【问题讨论】:

    标签: android facebook-sdk-4.x


    【解决方案1】:

    根据文档here

    setImageUrl 应该使用URL,而不是 Android 平台中的统一Uri。

    a imageURL,将出现在帖子上的缩略图的 URL

    该库的 java 文档也明确表示 A network URL of image

    public ShareLinkContent.Builder setImageUrl(@android.support.annotation.Nullable android.net.Uri imageUrl)
    Set the URL of a picture to attach to this content.
    Parameters:
        imageUrl - The network URL of an image.
    Returns:
        The builder.
    

    【讨论】:

    • 这意味着我必须通过互联网指定图像的 URL 来设置图像 URL。不能是内部应用镜像?
    • @tuanpm 没有。图片应该位于Network。您可以将照片上传到照片服务提供商或您自己的服务器,然后使用它。
    猜你喜欢
    • 1970-01-01
    • 2016-04-12
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多