2

I'm using Facebook Android SDK 4.+ to share photo by a button click in my app.

When user click the button, it will open the Facebook share photo page. After posting the photo I want to show alertbox which telling that photo has succesfully posted.

I've been using this

SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(bitmap)
            .build();
    SharePhotoContent content = new SharePhotoContent.Builder()
            .addPhoto(photo)
            .setShareHashtag(new ShareHashtag.Builder()
                    .setHashtag(hastag).build())
            .build();

    ShareDialog.show(SellingActivity.this,content);

By putting the alertbox after sharedialog.show didn't seem work. It would end up showed after button clicked, then facebook share photo page would show up after that.

ADM
  • 20,406
  • 11
  • 52
  • 83
BrenDonie
  • 85
  • 1
  • 10
  • Add callback to `ShareDialog` and show the `AlerrtDialog` on Success . Have alook at [This Discussion](https://stackoverflow.com/questions/30155059/facebook-android-sdk-sharedialog-callback-is-always-success). – ADM Mar 15 '18 at 04:08

1 Answers1

1

If you use this method of share ShareDialog.show(SellingActivity.this,content); there won't be anycallback. Look at there documention -

/**
 * Helper to show the provided {@link com.facebook.share.model.ShareContent} using the provided
 * Fragment. No callback will be invoked.
 *
 * @param fragment android.support.v4.app.Fragment to use to share the provided content
 * @param shareContent Content to share
 */
public static void show(
        final Fragment fragment,
        final ShareContent shareContent) {
    show(new FragmentWrapper(fragment), shareContent);
}

If you want callback then we have to use CallbackManager and we need to register for Callback.

In summary below is what you need to do -

  1. Create CallbackManager

    CallbackManager callbackManager = CallbackManager.Factory.create();

  2. Create ShareDialog

    ShareDialog shareDialog = new ShareDialog(activity or fragment);

  3. Register for callback

shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
            @Override
            public void onSuccess(Sharer.Result result) {

            }

            @Override
            public void onCancel() {

            }

            @Override
            public void onError(FacebookException error) {

            }
        });
  1. Override onActivityResult

@Override public void onActivityResult(int requestCode, int resultCode, Intent data { super.onActivityResult(requestCode,resultCode, data); callbackManager.onActivityResult(requestCode,resultCode, data); }


Community
  • 1
  • 1
Nagesh Jatagond
  • 344
  • 2
  • 13