I'm developing an app, that will be installed on one device and every user will use my device to share an image.
They need to login on Facebook
to share the image on their profile. After sharing the image, the app should logout from facebook in order to let the next user to login.
For this reason, I'm not using the Facebook Android app, but opted for the webview alternative.
After a user login, it opens a WebView
(on Chrome
) with the login and ask username, password and then permission.
The user publish the image, and the app calls:
LoginManager.getInstance().logOut();
When the next user comes, clicks on login with Facebook
, it opens a WebView
which says that I've already accessed this app from that Facebook
account so I can just click on continue - there isn't even a logout button.
This is because it uses the precedent user session, which is still logged in inside the WebView
.
I would need a way to logout the user from the WebView
. I'm using Facebook sdk 4.31.0
.
I've tried to Clear Cookies using the method described in this answer, but dosen't work:
public static void clearCookies(Context context)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
Log.d(TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
} else
{
Log.d(TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1));
CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context);
cookieSyncMngr.startSync();
CookieManager cookieManager=CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
}
}
And then:
WebView mWebView = new WebView(getApplicationContext());
mWebView.clearCache(true);
mWebView.clearHistory();
clearCookies(getApplicationContext());
The user is still logged in on chrome. Even thought, this works on "Browser" app (available on older devices).