Chrome Custom Tabs for Android

Working with Custom Tabs isn’t exactly straightforward. Even minimal examples involve quite a bit of code:

What makes it worse is that one can’t expect Chrome to be available on any device. That means additional code to fall back to good old WebView. To simplify the experience, there is a new library available that provides a higher-level interface that implements many often-needed convenience features:

To create a new CustomTabsIntent and start it with a keep-alive service as well as a fallback:

CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()

// This is optional but recommended
CustomTabsHelper.addKeepAliveExtra(this, customTabsIntent.intent);

// This is where the magic happens...
CustomTabsHelper.openCustomTab(this, customTabsIntent,
new WebViewFallback());

Preload CustomTabs in your to warm-up early and reduce start-up time:

// Preload custom tabs service for improved performance
// This is optional but recommended

This is how it looks:

Now Custom Tabs are great again!