Facebook Session cancel dialog

2019-05-10 09:53发布

I'm developping an app that uses this : https://developers.facebook.com/docs/android/native-login/

I have followed the Facebook dev tutorial, so basically I have the session check, it opens the dialog, and I'm trying to get the Cancel event (when the user cancel the facebook dialog) but I have no method on this.

Maybe you can help.

Thanks

EDIT: Actually, even if I click the cancel button, I still receive the GraphUser correctly. That's weird.

2条回答
小情绪 Triste *
2楼-- · 2019-05-10 10:30

Add a Session.StatusCallback to your open request where you can check the SessionState.

       new Session.StatusCallback() {

            @Override
            public void call(Session session, SessionState state, Exception exception) {
                        //check state
            }

        };

Check out this question.

查看更多
仙女界的扛把子
3楼-- · 2019-05-10 10:31

With Android SDK 3.5, I got the cancel event via exception, if the state change callback with instance of FacebookOperationCanceledException or FacebookAuthorizationException, its an cancel event:

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException) {

        // Cancelled by user, show alert
        new AlertDialog.Builder(this).setTitle(R.string.cancelled).setMessage(R.string.permission_not_granted).setPositiveButton(R.string.ok, null).show();

    } else {

        Session session = Session.getActiveSession();
        if ((session != null && session.isOpened())) {
            // Session ready
        }
    }
}

private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

It works just great

查看更多
登录 后发表回答