How to launch any URL into Chrome Custom Tab as non-logged in

4.5k views Asked by At

I have an android sample app where I want to open any URL into Chrome Custom Tab instead of WebView. I am trying from https://developer.chrome.com/multidevice/android/customtabs and able to do this.

Here I'm facing a problem and that is -

If I already logged-in into facebook from Chrome Browser, then it is also shown as logged-in when I launch facebook url into Chrome Custom Tab.

It seems like Chrome Custom Tab is using the cookies of Chrome Browser. But I want to launch any URL into Chrome Custom Tab as "non-logged-in" state regardless the login state of Chrome Browser.

The problem is that I didn't find any way to clear cookies of chrome custom tab, although previously I cleared cookies by "cookieManager.removeAllCookie()" for webview.

Is it possible to clear cookies of chrome custom tab before launch URL, can anyone please help to achieve this ?

Here is my code to lauch URL into chrome custom tab -

private void launchURL(String url) {
    CustomTabsIntent.Builder builderCustomTabs = new CustomTabsIntent.Builder();
    CustomTabsIntent intentCustomTabs = builderCustomTabs.build();
    intentCustomTabs.intent.setPackage("com.android.chrome");
    intentCustomTabs.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentCustomTabs.launchUrl(this, Uri.parse(url));
}
1

There are 1 answers

3
diegot On

I have done something like this with my own app. In my case, I used a URL which logs the user out and redirects to the login page.

After some research about Facebook logout URL, I find that it is possible only if you have the user token. The only way I thought you can manage this, is creating a web page to execute some JavaScript code (using Facebook SDK) to log the user out of Facebook, then you can redirect him to Facebook log in page. I never tested it, but maybe it will work.