I'm trying to implement Facebook Log In Button in Android.
Currently when I click the button the facebook app opens with no problems, but when I accept or cancel the callbacks are not getting called. Here is my code.
Public class AccessOptionsFragment extends Fragment implements FacebookCallback<LoginResult> {
private CallbackManager callbackManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
View view = inflater.inflate(R.layout.fragment_access_options, container, false);
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) view.findViewById(R.id.fb_button);
loginButton.setFragment(this);
loginButton.setReadPermissions("email");
loginButton.registerCallback(callbackManager, this);
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return view;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, requestCode, data);
}
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
AccessActivity accessActivity = (AccessActivity)this.getActivity();
accessActivity.displaySignUpActivity(accessToken);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
}
Already checked the manifest and it seems to be ok.
If you need anything else to help me please tell me. I've been reading answers but none have worked.
EDIT --> SOLUTION
For some reason, as mentioned in the comments, the Fragment onActivityResult() was not getting called, but instead the Activity was.
So move the facebook logic to the activity and the let the fragment just manage the view. And REMEMBER TO DELETE THE LINE
loginButton.setFragment(this);
Otherwise the callback won't work.