I have set up simple facebook login. For Android 2.3.6 everything works as should, user gets prompt login dialog, enters data and app goes on. I thought that it was android versions fault but it turs out that the login isn't working when there is facebook application installed on the phone!
Tested this on: Galaxy Ace 2.3.6 HTC Desire 4.1.2 Galaxy Note 4.1.2 Android emulator 4.1.2
Even the facebook samples are not working!
Every time the app is executing - else {
Log.d("SESSION NOT OPENED", "SESSION NOT OPENED");
}
It seems like session isn't opened but why is that? Followed this guide - https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
Code:
Session.openActiveSession(this, true, new Session.StatusCallback() {
@Override
public void call(final Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Log.d("Access_token", session.getAccessToken());
}
}
});
} else {
Log.d("SESSION NOT OPENED", "SESSION NOT OPENED");
}
}
});
i am writting this answer for those who are using Facebook SDK 4.X
you can open login portal of facebook in either of the two ways :
if you have an android device with Android 1.9.X
and Facebook App
is Installed in device called Native Login
Method here, you don't need to use facebook WebView
if you have not installed Facebook App
in your Android device then it's good to use WebView
so for this Facebook provide 3 Constants
NATIVE_ONLY
(used when you want to open in Facebook App only)WEB_ONLY
(used when you want to open in WebView
only)NATIVE_WITH_FALLBACK
(Recommended Facebook detect and opne webView
if app is not installed)Check below link for detail https://developers.facebook.com/docs/reference/android/current/class/LoginButton/ https://developers.facebook.com/docs/facebook-login/android/v2.2#troubleshooting
LoginButton.setLoginBehavior(LoginBehavior.NATIVE_WITH_FALLBACK);
LoginButton.setLoginBehavior(LoginBehavior.NATIVE_ONLY);
LoginButton.setLoginBehavior(LoginBehavior.WEB_ONLY);