For the solution on your link, I believe the source code taken from here. As you can see from CustomTabActivityHelper#openCustomTab, first it will look for the app that support Custom Tabs. If it is available, then start the implicit intent described by CustomTabsIntent. If not, open the WebViewActivity.
But, if what you want is just providing fallback mechanism, it should not be that complicated. Here is the simpler code:
public class CustomTabs { private static final String ACTION_CUSTOM_TABS_CONNECTION = "android.support.customtabs.action.CustomTabsService"; private static final String STABLE_PACKAGE = "com.android.chrome"; private static final String BETA_PACKAGE = "com.chrome.beta"; private static final String DEV_PACKAGE = "com.chrome.dev"; private static final String LOCAL_PACKAGE = "com.google.android.apps.chrome"; public static void openTab(Context context, String url) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); /* do some UI customization here */ CustomTabsIntent customTabsIntent = builder.build(); String packageName = getPackageNameToUse(context); if (packageName == null) { Intent intent = new Intent(context, WebviewActivity.class); intent.putExtra(WebviewActivity.EXTRA_URL, url); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(intent); } else { customTabsIntent.intent.setPackage(packageName); customTabsIntent.launchUrl(context, Uri.parse(url)); } } private static String getPackageNameToUse(Context context) { String packageNameToUse = null; PackageManager pm = context.getPackageManager(); Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); String defaultViewHandlerPackageName = null; if (defaultViewHandlerInfo != null) { defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; } List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); List<String> packagesSupportingCustomTabs = new ArrayList<>(); for (ResolveInfo info : resolvedActivityList) { Intent serviceIntent = new Intent(); serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); serviceIntent.setPackage(info.activityInfo.packageName); if (pm.resolveService(serviceIntent, 0) != null) { packagesSupportingCustomTabs.add(info.activityInfo.packageName); } } if (packagesSupportingCustomTabs.isEmpty()) { packageNameToUse = null; } else if (packagesSupportingCustomTabs.size() == 1) { packageNameToUse = packagesSupportingCustomTabs.get(0); } else if (!TextUtils.isEmpty(defaultViewHandlerPackageName) && !hasSpecializedHandlerIntents(context, activityIntent) && packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) { packageNameToUse = defaultViewHandlerPackageName; } else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) { packageNameToUse = STABLE_PACKAGE; } else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) { packageNameToUse = BETA_PACKAGE; } else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) { packageNameToUse = DEV_PACKAGE; } else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) { packageNameToUse = LOCAL_PACKAGE; } return packageNameToUse; } private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { try { PackageManager pm = context.getPackageManager(); List<ResolveInfo> handlers = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); if (handlers == null || handlers.size() == 0) { return false; } for (ResolveInfo resolveInfo : handlers) { IntentFilter filter = resolveInfo.filter; if (filter == null) continue; if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; if (resolveInfo.activityInfo == null) continue; return true; } } catch (RuntimeException e) { Log.e("LOG", "Runtime exception while getting specialized handlers"); } return false; } }