Michael
Michael

Reputation: 53

Is it possible to make a Chrome CustomTabs intent not open an external application?

I want the Chrome CustomTab to always open the url in the Chrome CustomTab. Even if there is an external application that the intent can go to. Right now the user is prompted if they want to open in Chrome or the external application. Is it possible to force the intent to go through Chrome? I know a WebView would work, but the CustomTab has more functionality...

Upvotes: 5

Views: 5633

Answers (2)

Code on the Rocks
Code on the Rocks

Reputation: 17764

In case the above answer doesn't solve your issue, you can occasionally add the "m." prefix to your URLs to get the mobile version of a website.

In my situation, opening "https://www.wikipedia.org" would always open the Wikipedia app and not a custom tab. Once I changed the URL to "https://en.m.wikipedia.org", the URL would always open in my Chrome Custom tab and even if the user navigates to different pages, they never leave my app.

Upvotes: 0

mdrafiqulrabin
mdrafiqulrabin

Reputation: 1697

This question is not clear to me. I think you wanted to say that you want always open the url in the Chrome Custom Tab without displaying choosing dialog for Chrome or any external application.

If my understanding is Okay, then in case of Chrome Browser, you should set the CustomTabIntent with the package of Chrome browser before launching the url.

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));
}

For details, check: custom chrome tabs asks for multiple browser to choose

Upvotes: 5

Related Questions