The first step for a Custom Tabs integration is adding the AndroidX Browser Library to your project. Open the app/build.gradle file and add the browser library to the dependencies section.
Checkout the Android Custom Tab Sample app on Github for a working example.
Open a link in a Custom Tab
String url = "https://developers.android.com";
CustomTabsIntent intent = new CustomTabsIntent.Builder()
This will open a fullscreen Custom Tab activity as seen on the following screenshot.
What happens if the user's default browser does not support Custom Tabs? Custom Tabs are supported by most Android browsers, but if no browser that supports Custom Tabs is installed, the
CustomTabIntent will open the user's default browser instead. This works, as the
CustomTabsIntent uses the
ACTION\_VIEW Intent with
Extras key to customize the UI.
Supporting Android App Links
By default, Custom Tabs support Android App Links. This means, if the YouTube app is installed, launching a
CustomTabsIntent with a YouTube video URL will open the YouTube app instead of the browser.
However, passing a
CustomTabsSession to a
CustomTabIntent will force open the link in a Custom Tab, even if the corresponding native app is installed. If you want to keep the default behavior of opening web links in native apps, you need to additionally follow our guide on how to check if a link can be handled by an installed native app.