0

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

我也尝试过使用drawable中的图像,但现象是一样的

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

任何人都可以帮助我!

4

1 回答 1

0

根据这里的文件

setImageUrl应该使用 a ,而不是在 Android 平台上URL统一。Uri

一个 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.
于 2016-08-03T03:30:57.397 回答