3

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.

1
  • Let's talk here: Link.
    – Vikram
    Sep 4, 2013 at 17:17

2 Answers 2

13
+50

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

8
  • Actually, no it's not working. I'm always getting inside the if (exception...). Never in the else. Sep 4, 2013 at 17:18
  • Since you are always getting into the if, lets check if it is an FacebookAuthorizationException but not FacebookOperationCanceledException? It could be possible that you did not set your Key Hashes correctly in your FB app setting. Sep 4, 2013 at 17:27
  • Look at the getting started correctly, for step 4 and 5: developers.facebook.com/docs/android/getting-started/… Sep 4, 2013 at 17:28
  • Okay now I got it right, but if the user clics on Cancel, I want to finish the activity that calls the facebook dialog. But finish() isn't doing the job. Sep 4, 2013 at 17:38
  • You are calling in an activity or fragment? if activity, replace the alert with finish(); should work. Else getActivity().finish(); Sep 5, 2013 at 2:11
0

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.

1
  • It's not exactly the same problem he has. I'm actually having problem handling the "Cancel" button on the native dialog. Aug 31, 2013 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.