I have integrated Facebook sdk in my android app. As described in the manual I added the login callback for facebook. But I have to change the UI if the user logs out from facebook. Where do I put that code. My code for login is
/**
* Login Callback for facebook login
*/
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
//Call updateUI()
setData("provider","facebook");
loginType = LoginTypes.FB_LOGIN;
isLoggedin = true;
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
txtName.setText(response.toString());
updateUI();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
editText_message.setText("Login Cancelled.");
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
To learn more about using Facebook development tools, see App Development. The current version of the Facebook SDK for Android is version 14.1. 1 and requires the Android API 15. Code and samples for the Facebook SDK for Android are available on GitHub.
there are 2 possible ways:
1) you need to overwrite in on create AccessTokenTracker like this:
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken,
AccessToken currentAccessToken) {
if (currentAccessToken == null) {
//write your code here what to do when user logout
}
}
}
2) You can call LoginManager.logOut() to log out the user
hope this will help you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With