A few days ago I implemented FB Login to my APP, and today I found out that most of the things I have implemented are now deprecated.
Before, I was using Session
to see if the user was logged in or not. However, that doesn't work with the new SDK.
According to their docs, we can use AccessToken.getCurrentAccessToken()
and Profile.getCurrentProfile()
to check if the user is already logged in, but I could not make use of those.
I tried something like this:
if(AccessToken.getCurrentAccessToken() == null)
I wonder if that would work if I could use it inside of this (which is also provided by FB):
LoginManager.getInstance().registerCallback(callbackManager, new LoginManager.Callback() {...});
However, I get a "Cannot resolve symbol 'Callback'".
EDIT!!!!!!
Alright, so I was able to check if the user is logged in by using the following:
On onCreate:
accessTokenTracker = new AccessTokenTracker() { @Override protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken newAccessToken) { updateWithToken(newAccessToken); } };
Then, that calles my updateWithToken
method:
private void updateWithToken(AccessToken currentAccessToken) { if (currentAccessToken != null) { LOAD ACTIVITY A! } else { LOAD ACTIVITY B! } }
Now, the problem is: If the user has used the application and hasn logged in before, I can check for that! But if it is the first time that the user is using the app, updateWithToken
is never called by my AccessTokenTracker.
I'd really appreciate if someone could help.
Thanks!
So far, to log out Facebook programmatically, I used : Session session = Session. getActiveSession(); session. closeAndClearTokenInformation();
Click on "Active Sessions," which is located towards the bottom of the Privacy settings page. This brings up a list of your current and past Facebook logins, including the location where the login took place, the type of device that was used to access the site, and the day and time of the login.
To check if the user is signed-in, call isConnected(). if (mGoogleApiClient != null && mGoogleApiClient. isConnected()) { // signed in.
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.
A much simpler solution worked for my case (I don't know if this is the more elegant way though):
public boolean isLoggedIn() { AccessToken accessToken = AccessToken.getCurrentAccessToken(); return accessToken != null; }
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