I post here because I've got a problem. I'm working on a new android application , and I want to know how I can detect when a user is disconnecting (facebook logout button), because I want to refresh my UI at this moment.
I have been watched the official documentation, but I found nothing.
To use the Facebook SDK in an Android Studio project, add the SDK as a build dependency and import the SDK. Go to Android Studio | New Project | Minimum SDK. Select API 15: Android 4.0. 3 (IceCreamSandwich) or higher and create your new project.
You can set a listener on the onCreate()
method on your activity
AccessTokenTracker accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(
AccessToken oldAccessToken,
AccessToken currentAccessToken) {
if (currentAccessToken == null){
//User logged out
}
}
};
You need to import com.facebook.AccessToken
and com.facebook.AccessTokenTracker
When you create the instance of AccessTokenTracker it implicitly starts tracking. For stopping tracking you should call AccessTokenTracker.stopTracking()
e.g. in onDestroy()
to not receive anymore events when not needed/wanted and especially to not leak memory!
You can get any time if the user is logged in/out by calling
AccessToken at = AccessToken.getCurrentAccessToken();
If the user is not logged in, you get a null
value.
For further reference please check the documentation at https://developers.facebook.com/docs/reference/android/current/class/AccessTokenTracker/
You can try this also
if(AccessToken.getCurrentAccessToken()!=null)
{
Log.v("User is login","YES");
}
else
{
Log.v("User is not login","OK");
LoginManager.getInstance().logInWithReadPermissions(WelcomeActivity1.this, (Arrays.asList("public_profile", "user_friends","user_birthday","user_about_me","email")));
}
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