I'm using Facebook login as described in the "Getting started" Document - https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(R.id.welcome);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
when using this code Facebook recognize the user (that loged-in in the Facebook app) and assumes that this is the user that I want to log in with.
let's say that I want to leave the decision what Facebook account to use to the user.
how can I do that?
things I've tried so far:
1)perform user log in like this:
SessionTracker sessionTracker = new SessionTracker(activity, new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
}
}, null, false);
if (sessionTracker.getSession() == null || sessionTracker.getSession().getState().isClosed()) {
sessionTracker.setSession(null);
Session session = new Session.Builder(activity).setApplicationId(activity.getString(R.string.fb_app_id)).build();
Session.setActiveSession(session);
}
final Session currentSession = sessionTracker.getSession();
if (!currentSession.isOpened()) {
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(activity);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("email", "publish_actions"));
openRequest.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);
openRequest.setCallback(new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
Request.executeMeRequestAsync(currentSession, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
authListener.onCompleteAuthorization(user != null, user, currentSession.getAccessToken(), currentSession.getExpirationDate().getTime());
}
});
}
});
currentSession.openForPublish(openRequest);
this works fine for the first time, but second time been called (Let's say after user loggin out from my app, and want to re-login with another facebook account) it remembers the last user that was logged in. !!even after uninstall Facebook app and my app!!!!
2) calling the same code before log in again:
if (Session.getActiveSession() != null) {
Session.getActiveSession().closeAndClearTokenInformation();
}
it does not do anything...
please help me understand how can I clear all previous Facebook user history / cached tokens, to achieve the following behavior:
every time user perform Facebook login - Facebook "enter Email + password" dialog will appear...
thanks in advance..