如何从Android应用程序分享纯文本到Facebook Messenger

时间:2015-07-26 10:34:05

标签: android facebook facebook-sdk-4.0 facebook-messenger

我正在尝试使用facebook sdk 4.x从我的应用程序中分享纯文本到messenger应用程序,但是我无法为此配置contentUri,但是当我发送图像时它可以工作。

如何为纯文本执行此操作?

Uri contentUri = Uri.parse("android.resource://in.darpankulkarni.l33ttxtformessenger/mipmap/ic_launcher");
// contentUri points to the content being shared to Messenger
   ShareToMessengerParams shareToMessengerParams =
        ShareToMessengerParams.newBuilder(contentUri, "image/png").setExternalUri(Uri.parse("https://montanaflynn-l33t-sp34k.p.mashape.com/encode?text=Hello+How+the+hell+are+you!&mashape-key=AD8dVisiLdmshFoLegK2hzNoDQI4p1BDlshjsn50fOqenOnPY7"))
                        .build();

// Sharing from an Activity
   MessengerUtils.shareToMessenger(
                this,
                REQUEST_CODE_SHARE_TO_MESSENGER,
                shareToMessengerParams);

如何使用上面的代码发送纯文本?

1 个答案:

答案 0 :(得分:2)

The supported MessengerUtils methods don't allow for sharing text. The following worked for me:

ShareLinkContent.Builder shareLinkContentBuilder = new ShareLinkContent.Builder()
        .setContentTitle(contentTitle)
        .setContentDescription(contentDescription)
        .setContentUrl(Uri.parse(url));
shareLinkContentBuilder.setImageUrl(Uri.parse(imageUrl));
MessageDialog messageDialog = new MessageDialog(activity);
messageDialog.registerCallback(callbackManager, callback);
messageDialog.show(shareLinkContentBuilder.build());

The share link content was obtained from: https://developers.facebook.com/docs/sharing/android