Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Session cancel dialog

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.

like image 371
Quentin DOMMERC Avatar asked Dec 06 '25 03:12

Quentin DOMMERC


1 Answers

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

like image 62
Jarod DY Law Avatar answered Dec 08 '25 17:12

Jarod DY Law



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!