Verificare se un dispositivo Android ha un browser che supporta le schede personalizzate?

Se vuoi sapere se il browser predefinito o qualsiasi browser di un dispositivo supporta le schede personalizzate, utilizza l'helper getPackageName in CustomTabsClient:

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

Puoi anche controllare se un browser sul dispositivo supporta le schede personalizzate:

// 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 ha introdotto modifiche alla visibilità dei pacchetti. Se la tua app per Android ha come target il livello API 30 o versioni successive, è necessario aggiungere la seguente sezione di query a AndroidManifest.xml, altrimenti lo snippet di codice riportato sopra non restituirà risultati:

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