Yaseen Ahmad Yaseen Ahmad - 1 year ago 82
Java Question

Android Application Login with Facebook is not working with Facebook App installed

This code is working well when I uninstalled the Facebook App but didn't work with Facebook App installed. I'm using Facebook SDK 4.0.

This is my code

package com.example.nhp04.gqfood;
import com.facebook.AccessToken;
import com.facebook.AccessTokenTracker;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.Profile;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;

public class Login extends AppCompatActivity implements Animation.AnimationListener {

private String info = "";
private LoginButton loginButton;
private CallbackManager callbackManager;
private AccessTokenTracker tracker;

protected void onCreate(Bundle savedInstanceState) {
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton)findViewById(R.id.login_button);

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
info = ("User ID: " +

loginResult.getAccessToken().getUserId() + "\n" + "Auth Token: " + loginResult.getAccessToken().getToken());

public void onCancel() {
info = ("Login attempt canceled.");

public void onError(FacebookException e) {
info = ("Login attempt failed.");
tracker = new AccessTokenTracker() {
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {


this function for checking login

public boolean isLoggedIn() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null;

this on Resume and on Stop methods

protected void onResume() {
if (isLoggedIn()){
Intent home = new Intent(this, home.class);

protected void onStop() {

And this is my onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Intent home = new Intent(this, home.class);
} else {
Toast.makeText(getApplicationContext(), "Unable to login please check your internet connection",Toast.LENGTH_LONG).show();

Answer Source

Your code is looks good i was also facing the same issue and fix it by updating my key store i recommend please check your key store I'm sure that will your key store problem. don't sure it will 100% help you but that was help me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download