login Facebook registerCallback not called

Jerome Ansia picture Jerome Ansia · Jun 2, 2015 · Viewed 8.3k times · Source

Here is my onCreate method:

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_social_login);
    init();
    hideActiveSocialNetworks();
    FacebookSdk.sdkInitialize(getApplicationContext());
    CallbackManager callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // not called
            Log.d("fb_login_sdk", "callback success");
        }

        @Override
        public void onCancel() {
            // not called
            Log.d("fb_login_sdk", "callback cancel");
        }

        @Override
        public void onError(FacebookException e) {
            // not called
            Log.d("fb_login_sdk", "callback onError");
        }
    });

    final Activity activity = this;

    findViewById(R.id.fb_login_sdk).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d("fb_login_sdk", "click");
            List<String> perm = new ArrayList<String>();
            perm.add("user_friends");
            LoginManager.getInstance().logInWithReadPermissions(activity, perm);
        }
    });
}

After login the onSuccess(), onCancel(), onError() methods are not fired.

Documentation: https://developers.facebook.com/docs/facebook-login/android/v2.3

Answer

Jerome Ansia picture Jerome Ansia · Jun 2, 2015

Missing this on my activity:

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