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...
-
Questions seeking help must include *the desired behavior*, *a specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – Gustavo Morales Jul 02 '16 at 05:29
2 Answers
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

- 1,657
- 5
- 28
- 38
-
5Beware that other browsers, such as Samsung Internet Browser and Firefox have implemented or are implementing support for Custom Tabs. By setting a hardcoded package to `com.android.chrome`, users who have set their preferred browser as something other than Chrome won't have their preferences honored, and your application may break on systems that don't have Chrome installed. The best practices explain how to create a code that works with other browsers: https://developer.chrome.com/multidevice/android/customtabs#bestpractices – andreban Feb 28 '17 at 19:43
-
2To add to @andreban's comment (since the Android/Chrome docs seem to have changed slightly): [Here](https://developer.chrome.com/docs/android/custom-tabs/integration-guide/#how-can-i-check-whether-the-android-device-has-a-browser-that-supports-custom-tab) they explain how one can determine all browsers that support Custom Tabs. – balu Jul 20 '22 at 13:06
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.

- 11,488
- 3
- 53
- 61
-
That's because Wikipedia has the mobile version website, there are apps/companies that doesn't. – Skizo-ozᴉʞS ツ May 27 '21 at 12:52