I am trying to track user profile with ProfileTracker class using new Facebook sdk version 4.5. When user login with Facebook in my app (and Facebook native app is installed in device) then it login successfully with current user account in native app. But now if user logout from the native Facebook app in the device and login with another user account than the previous one. I want my app to get notify that now user has changed his account/profile in native app. TO acheive that i am using following code:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_homescreen);
uIint();
LoginManager.getInstance().registerCallback(callbackManager, this);
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
if (oldProfile != null) {
Log.i(getClass().getSimpleName(), "profile oldProfile: " + oldProfile.getFirstName());
}
if (currentProfile != null) {
Log.i(getClass().getSimpleName(), "profile currentProfile: " + currentProfile.getFirstName());
}
}
};
profileTracker.startTracking();
if(profileTracker.isTracking())
Log.i(getClass().getSimpleName(), "profile currentProfile Tracking: " + "yes");
else
Log.i(getClass().getSimpleName(), "profile currentProfile Tracking: " + "no");
}
@Override
public void onSuccess(LoginResult loginResult) {
//Utils.showToast_msg(context, "Login success");
getFbProfileInfo();
}
@Override
public void onCancel() {
Utils.showToast_msg(context, "Login onCancel");
}
@Override
public void onError(FacebookException e) {
Utils.showToast_msg(context, "Login onError");
}
I login with an account in native Fb app and then login with fb in my app successfully. Then i logout from native Fb app and login with another account but onCurrentProfileChanged never gets called to notify me that profile has chagned. I print a log to check if it is tracking the profile or not it always return true/yes. Any help?
onCurrentProfileChanged()
will only be called if you log the user out explicitly using LoginManager.getInstance().logOut()
and then try to authenticate the user with Facebook using LoginManager
's logIn
methods.
Your app will not be aware that the user has logged into another account in the Facebook native app, ProfileTracker
only watches the Profile
that is used to log in to your app and not what's outside of it.
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