I’m completely flabbergasted by the Facebook SDK for Android–it’s quite challenging to use effectively. As I understand it, these are the rules for single sign on:
- If a user has the Facebook app and logs into a third-party app using the SDK, the Facebook app is logged in as well
- If the user logs out of the third-party app using the SDK, the Facebook app is still signed in (probably for the best)
- If the user logs out of the Facebook app, the third-party app using the SDK is unaffected
Is there a way, in an Android app using the Facebook SDK, to check and see if the official Facebook app is NOT signed into the same account the Android app is using, and if that is the case, sign out of the Android app… in other words, if you go into the Facebook app and sign out, then go to the third-party app, it will be logged out?
Updated answer
If I understand this right, you’re asking if we can:
Short answer: No, but you can, by writing your own Facebook class
Long answer:
Single Single On(SSO) is handled in the Facebook class in the Facebook Android SDK. The Facebook class API doesn’t have methods that let you access or modify the SSO process.
In the Facebook class, there are four overloaded public authorize methods. Three of them call the fourth:
Here, the SSO process starts. It checks for SSO like so:
The private startSingleSignOn method checks if the official Facebook app can manage the Auth process:
The method creates an explicit intent for the class ProxyAuth in the package com.facebook.katana, which is the offical Facebook app’s package.
The method then calls validateActivityIntent with the intent as a parameter. It returns true if the service intent resolution happens successfully and the FB signatures match.
We don’t have access to the ProxyAuth class source but based on the observed app behaviour you described in your question and comments, it seems that ProxyAuth only completes the auth process if the user is logged in on the official app to the same account as on your app. This means that there is no way to distingush – from your app – between 1) the offical FB app not being installed 2)the official FB app not being in a logged in state, and 3) it being logged into another account.
So you can do this:
But you can’t
If what you can do as per above meets your needs to trigger a sign-out, you need to write your own custom Facebook class to add the new logic. The Facebook class in the Facebook Android SDK doesn’t extend an abstract class, only Object implicitly, so you need to replicate the Facebook code into your CustomFacebook class and modify it to add code that forces the log-out.
For reference:
Old answer
I’m not sure this answers your question but to force a user log-out with the Facebook Android SDK, use the FORCE_DIALOG_AUTH flag when you call authorize() during auth/login, like so:
where mFacebook is an instance of the SDK’s Facebook class, and LoginDialogListener implements DialogListener.
If the user logs out, the login dialog will now appear next time the user wants to login or starts your app.
If you don’t set the FORCE_DIALOG_AUTH flag the user will be ‘automatically’ logged in.