0

So for the past few days I've been trying to get my head around the Facebook SDK for android. I've managed to get the user to log in but only by using

        loginBtn.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);

This means every time the user goes to the activity containing the login button they are forced to re-enter their details (username and password) every time. I've followed the tutorials provided on the facebook developers site however I still can't manage to get a simple one time login working. The whole point of this is that I'm trying to get a very simple straight forward image upload button. Press button - check if logged in, if not, login - once logged in post image. But I'm just having trouble with keeping a constant login state, I have managed to get the upload image working however like I said, once the user goes to a different activity they are forced to login again. Surely it should only force them to once on the button click.

user2756111
  • 79
  • 1
  • 9

1 Answers1

0

Check if they are logged in already:

facebook.isSessionValid()

Better way to do this:

public boolean isLoggedIn() {
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
        return true;
    } else {
        return false;
    }
}
Community
  • 1
  • 1
  • This is great, thanks for the help works a charm. One more thing, because I am forcing the user to login if there is no active session, the window that appears requires them to re enter all their details, if there a way to save what they enter and then load it into the force login page in the future? – user2756111 Feb 27 '14 at 14:31
  • @user2756111 Not that I know of. Maybe there is something deep in the API (https://developers.facebook.com/docs/android/login-with-facebook/) about that. I would highly recommend **not** manually saving credential info because that would be illegal. – But I'm Not A Wrapper Class Feb 27 '14 at 15:05