使用facebook-android-sdk与本地图像分享Android App中的链接

时间:2016-08-03 03:05:32

标签: android facebook-sdk-4.x

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

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();
}

我也尝试过来自drawable的图像,但现象是相同的

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

任何人都可以帮助我!!

1 个答案:

答案 0 :(得分:0)

根据文件here

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

  

imageURL,将在帖子上显示的缩略图图片的网址

该库的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.