3
votes

I am using Facebook Android SDK version 4.25 and ShareLinkContent, ShareDialog for posting to Facebook on user behalf using my app.

This is the dialog which opens when user clicks my app's share functionality

enter image description here

There are two cross icons in sharedialog as you can see in the image. When i am clicking upper cross icon, sharedialog closes and onCancel callback is called.

Problem is when i am clicking lower cross icon onSuccess callback is being called same when i am clicking Post button. I want to give user some points when he shares post to Facebook. But i am getting success callback on lower cross icon as well. What to do? Thank You.

This is the callback code i am using :-

shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {

    @Override
    public void onSuccess(Sharer.Result result) {

            Log.e(LOG_TAG, "Facebook share success " + result.getPostId());

    }

    @Override
    public void onCancel() {

            Log.e(LOG_TAG, "Facebook share cancel");

    }

    @Override
    public void onError(FacebookException error) {

            Log.e(LOG_TAG, "Facebook share error");

    }

});
1

1 Answers

1
votes

When you click the upper cross, you are actually closing your own dialog box, that calls onCancel. But when click on the lower cross, it actually is in facebook view. So the callback is returned from facebook not your dialog. Try:

@Override
public void onSuccess(Sharer.Result result) {
   Log.e(LOG_TAG, "Facebook share success " + result.getPostId());
   //Notice this post id in both, cross click and when the status is updated successfully
   //So, if you don't get a valid post id returned, you can count it as a cancel.
}