简体   繁体   English

使用facebook-android-sdk和本地图像共享来自Android App的链接

[英]Share a link from Android App using facebook-android-sdk with local image

My android application using facebook-android-sdk:4.14.0 to share a link. 我的Android应用程序使用facebook-android-sdk:4.14.0共享链接。 I used ShareLinkContent to create share content and call setImageUrl() to specify image. 我使用ShareLinkContent创建共享内容,并调用setImageUrl()指定图像。 I want to use image from my app (not from a internet url link) to show on share post. 我想使用我的应用程序中的图像(而不是来自Internet URL链接)显示在共享帖子上。 I already tried as below code but it not work: 我已经尝试过以下代码,但无法正常工作:

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

I also tried with image from drawable but the phenomenon was same 我也尝试了可绘制的图像,但现象是相同的

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

Anyone can help me !! 任何人都可以帮助我!

According to the document here 根据这里的文件

setImageUrl should use a URL , not a uniformed Uri in Android platform. setImageUrl应该使用URL ,而不是Android平台中的统一Uri

a imageURL, the URL of thumbnail image that will appear on the post imageURL,将显示在帖子上的缩略图的URL

Also the java docs of the library has clearly say A network URL of image 此外,该库的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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM