カスタムタブをサポートするブラウザが Android デバイスにあるかどうかを確認します。

デフォルトのブラウザまたはデバイス上のブラウザがカスタムタブに対応しているかどうかを確認するには、CustomTabsClientgetPackageName ヘルパーを使用します。

String packageName = CustomTabsClient.getPackageName(
        context, 
        Collections.emptyList()
);
if (packageName == null) {
    // Custom Tabs are not supported by the default browser
}

また、デバイス上のブラウザがカスタムタブに対応しているかどうかも確認できます。

// Get all apps that can handle VIEW intents and Custom Tab service connections.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> viewIntentHandlers = packageManager.queryIntentActivities(activityIntent, 0);
// Get a package that supports Custom Tabs
String packageName = CustomTabsClient.getPackageName(
        context, 
        viewIntentHandlers,
        true /* ignore default */
);
if (packageName == null) {
    // Custom Tabs are not supported by any browser on the device
}

Android 11 では、パッケージの公開設定の変更が導入されました。Android アプリが API レベル 30 以降をターゲットとしている場合は、以下のクエリ セクションを AndroidManifest.xml に追加する必要があります。追加しないと、上記のコード スニペットで結果が返されません。

<queries>
    <intent>
        <action android:name=
            "android.support.customtabs.action.CustomTabsService" />
    </intent>
</queries>