Search code examples
androidfacebook-sdk-4.0

Share with Facebook Messenger


I have updated the dependency of Facebook SDK to 4.1.0. They changed a lot and now I cannot find a way to share text and image with Messenger.

Before updating the sdk I was using:

FacebookDialog.MessageDialogBuilder builder = new FacebookDialog.MessageDialogBuilder(this)
            .setName(linkName)
            .setDescription(description)
            .setLink(webLink)
            .setPicture(pictureLink);

    FacebookDialog dialog = builder.build();
    dialog.present();

Now looks like I can only share images.

String mimeType = "image/jpeg";
ShareToMessengerParams shareToMessengerParams =
        ShareToMessengerParams.newBuilder(contentUri, mimeType)
                .build();
MessengerUtils.shareToMessenger(
       this,
       REQUEST_CODE_SHARE_TO_MESSENGER,
       shareToMessengerParams);

Can anyone explain a equivalent way to share text and image as before 4.1.0 please?


Solution

  • I found out that there is a similar way to share on Facebook which works also for Messenger.

    Here is the code

    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 relative doc is under Sharing section and not Messenger one https://developers.facebook.com/docs/sharing/android