概要
例えば AndroidManifest.xml の <intent-filter>
に
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
と定義していた場合、Chrome Custom Tabs で https://example.com/
のページを表示しようとすると
intent-filter の条件に一致するため、

こんな感じで Chrome 以外の候補が表示されてしまいます。
この候補モーダルを表示させずに強制的に Chrome で表示する方法です。
方法
MainActivity.kt
val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
val customTabsIntent: CustomTabsIntent = builder.build()
if (packageManager.getLaunchIntentForPackage("com.android.chrome") != null) {
customTabsIntent.intent.setPackage("com.android.chrome")
}
customTabsIntent.launchUrl(this, Uri.parse(url))
setPackage()
で Chrome のパッケージ名を指定してあげるだけです。
念のため getLaunchIntentForPackage()
で Chrome が存在しているかチェックしています。
↑ では存在しなかったときの処理はなにも行っていませんが本来であればエラーメッセージを表示するなどしてあげたほうが良いかと思います。
以上です。