Facebook Intent share doesnt show Activity result

2019-09-10 09:13发布

I applied a facebook share on my app which of course includes a login but the problem is that when I shared a content to facebook the onActivityResult doesn't give any return. Following the facebook share guide here I implemented everything and shares successfully on both with and withouth facebook app installed. the only difference is that I can get the result on webview but not on intent. Here's my code on the activity result:

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

        Log.e("Activity","You wa shock!");

        uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
            @Override
            public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
                Log.e("Activity", String.format("Error: %s", error.toString()));
            }

            @Override
            public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
                boolean didCancel = FacebookDialog.getNativeDialogDidComplete(data);
                String completionGesture = FacebookDialog.getNativeDialogCompletionGesture(data);
                String postId = FacebookDialog.getNativeDialogPostId(data);

                if (didCancel)
                {
                    if (completionGesture == null || FacebookDialog.COMPLETION_GESTURE_CANCEL.equals(completionGesture)){
                        Toast.makeText(getActivity(),"CANCELLED",Toast.LENGTH_SHORT).show();
                    }
                    else{
                        // track post
                        Toast.makeText(getActivity(),"POSTED",Toast.LENGTH_SHORT).show();
                    }
                }
                else
                {
                    Toast.makeText(getActivity(),"CANCELLED",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

The other part of the code is just a copy paste exactly on what the tutorial have but for this part even the first log I placed doesn't show up even though I already OAuth'd my app and login successfully.

1条回答
手持菜刀,她持情操
2楼-- · 2019-09-10 09:50

You need to do

shareFacebookDialog.setFragment(this);

where "this" is the fragment
to get the callback in the fragment

查看更多
登录 后发表回答