且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在不使用 Facebook sdk 的情况下通过 Facebook 上的 Intent 共享文本

更新时间:2022-10-14 22:43:41

您无法使用 android shareIntent 在 Facebook 中单独共享文本.

只能通过 Facebook SDK 使用共享链接功能.

如果有图片,Facebook 会简单地忽略来自意图的额外文本.您可以分享图片,但不允许分享文字内容.

不幸的是,Facebook 共享意图只能采用带有前缀 http://的单个 URL,并且没有额外的文本消息.实际上 facebook 去掉了文本内容,只允许 URL/Link.这是设计使然,我们无法控制它.

这会起作用

IntentsharingIntent = new Intent(android.content.Intent.ACTION_SEND);sharedIntent.setType("text/plain");sharedIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");startActivity(Intent.createChooser(sharingIntent, "Share via"));

这行不通.

IntentsharingIntent = new Intent(android.content.Intent.ACTION_SEND);sharedIntent.setType("text/plain");sharedIntent.putExtra(Intent.EXTRA_TEXT, "从应用程序共享文本");startActivity(Intent.createChooser(sharingIntent, "Share via"));

您可以在 Facebook ***享文本的唯一方法是使用 FacebookSDK.

参考链接

Facebook 的 Android 共享意图-共享文本和链接

无法通过链接分享文本通过 Android Share Intent

Android 和 Facebook 分享意图

As Facebook doesn't allow sharing text via Intent unless we use Facebook sdk, I am looking for a way around to achieve this.

I can think of 3 hacks which I can use:

1) As Facebook allows image sharing, I can generate a Bitmap with sharing text drawn onto it and share the image using Intent.

2) Facebook allows sharing URLs, for which it also displays the Head of the page while sharing. I can host a dedicated page on my server and pass values as parameter in the url, and generate the Head using it.(I have no experience with php, but I guess this is possible)

3) Copy text to clipboard and notify user about this.

OR

Use combinations of all 3.

Can anyone suggest me a much better way around to share my content on Facebook without using Facebook sdk?

Thanks in advance.

There is no way you can share Text alone in the Facebook using android shareIntent.

It is possible only through Facebook SDK using share links functions.

Facebook simply ignores the Extra Text from the intent if there is an image. You can share image, but it does not allow you to share the Text content.

Unfortunately the Facebook sharing intent can only take a single URL with prefixed http:// and no additional text message. Actually facebook strips out the text content and allows only URL/Link. It is by Design and we have no control over it.

This will work

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
startActivity(Intent.createChooser(sharingIntent, "Share via"));

This will not work.

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Share Text from App");
startActivity(Intent.createChooser(sharingIntent, "Share via"));

Only approach you can share the text in the Facebook is using Facebook SDK.

Reference Links

Android share intent for facebook- share text AND link

Unable to share text with a link through Android Share Intent

Android and Facebook share intent