androidfacebookfacebook-graph-apifacebook-android-sdkfacebook-share

How to set post caption in Facebook Share using ShareLinkContent in Android?


I am developing an Android app. In my app, I am integrating Facebook API because I am sharing content from my app to Facebook. I am especially sharing link. So I am using ShareLinkContent option from official Facebook docs. I can successfully share on Facebook. But I am having a problem with this ShareLinkContent option because I cannot set the caption to post that is entered by user.

This is how I share to Facebook:

final ShareLinkContent content = new ShareLinkContent.Builder()
      .setContentTitle(shareTitle)
      .setImageUrl(Uri.parse(shareImageUrl))
      .setContentUrl(Uri.parse(shareContentUrl))
      .setContentDescription(shareDescription)
      .build();
ShareApi.share(content, null);

I display preview before I share like this:

enter image description here

As you can see now, I can only show preview. But what I want is I want to add an EditText in the preview. The text entered will be shared as post caption on Facebook. But the problem is there is no option setCaption(textUserEntered) in the ShareLinkContent option. I also mentioned options available in the preview image as well.

How can I set post option for ShareLinkContent? That content will be entered by user. How can I get it? Is it possible to use with ShareLinkContent?


Solution

  • I found the solution. Actually I do not need to show custom preview to user. If I build the share content like below code, preview will the option to enter post caption will be automatically added.

          final ShareLinkContent content = new ShareLinkContent.Builder()
                        .setContentTitle(shareTitle)
                        .setImageUrl(Uri.parse(shareImageUrl))
                        .setContentUrl(Uri.parse(shareContentUrl))
                        .setContentDescription(shareDescription)
                        .build();
          ShareDialog shareDialog = new ShareDialog(this);
          shareDialog.show(content);
    

    So no need to use

         ShareApi.share(content, null);