Facebook login Android application does not work with Facebook application installed

This code works well when I uninstalled the Facebook application , but did not work with the installed Facebook application. I am 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) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); setContentView(R.layout.activity_login); loginButton = (LoginButton)findViewById(R.id.login_button); loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override 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()); } @Override public void onCancel() { info = ("Login attempt canceled."); } @Override public void onError(FacebookException e) { info = ("Login attempt failed."); } }); System.out.println(info); tracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) { } }; tracker.startTracking(); } } 

this function to verify entry

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

this is according to the methods Resume and on Stop

 @Override protected void onResume() { super.onResume(); if (isLoggedIn()){ Intent home = new Intent(this, home.class); startActivity(home); } } @Override protected void onStop() { super.onStop(); tracker.stopTracking(); finish(); } 

And this is my onActivityResult

 @Override 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); startActivity(home); } else { Toast.makeText(getApplicationContext(), "Unable to login please check your internet connection",Toast.LENGTH_LONG).show(); } } 
+8
java android sdk facebook-android-sdk
source share
3 answers

where is your onActivityResult() code. In onActivityResult() you need to use a callbackmanager . User ID:

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

above will work as in fragment / activity. Make sure you have

 1. facebook app installed on your testing device 2. In facebook developer account check whether you have mentioned - correct package name : refer your android project manifestfile.xml - check that have you mentioned correct launcher class - Check that you have given correct debug/release hash key 3. Cross check your facebook application id and that mentioned in your manifestfile.xml facebook meta data are same 

In your code, change below

create a callbackmanager after setContentView(...) ;

change it below FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); setContentView(R.layout.activity_login); callbackManager = CallbackManager.Factory.create(); FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); setContentView(R.layout.activity_login); callbackManager = CallbackManager.Factory.create();

Remember, if this is a problem with you on facebook, then your problem is not to waste time looking for another thing. Also add a log failure method in the facebook sdk callback.

Post a comment if you still have a problem

+1
source share

You can delete your application in your facebook application. how can you open facebook app in go setup β†’ account setup β†’ app β†’ youer app β†’ remove. after uninstalling youer application, uninstall your application. and reinstall it and check that facebook login is working or not.

0
source share

Please change the version of your photo album on facebook, after you clean and rebuild the application, it will work

0
source share

All Articles