Handle `ActivityNotFoundException` when launching Chrome custom tab

Fixes #1068
pull/1090/head
Simon Marquis 2 years ago
parent a5c030f740
commit df2a1d545b
No known key found for this signature in database
GPG Key ID: AC8D63F7571DC6D6

@ -16,8 +16,10 @@
package com.google.samples.apps.nowinandroid.core.ui
import android.content.ActivityNotFoundException
import android.content.Context
import android.net.Uri
import android.widget.Toast
import androidx.annotation.ColorInt
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
@ -101,7 +103,11 @@ fun launchCustomChromeTab(context: Context, uri: Uri, @ColorInt toolbarColor: In
.setDefaultColorSchemeParams(customTabBarColor)
.build()
customTabsIntent.launchUrl(context, uri)
try {
customTabsIntent.launchUrl(context, uri)
} catch (e: ActivityNotFoundException) {
Toast.makeText(context, R.string.core_ui_custom_tab_activity_not_found, Toast.LENGTH_LONG).show()
}
}
/**

@ -26,4 +26,6 @@
<string name="core_ui_topic_chip_content_description_when_followed">%1$s is followed</string>
<string name="core_ui_topic_chip_content_description_when_not_followed">%1$s is not followed</string>
<string name="core_ui_custom_tab_activity_not_found">Please install a browser to open this news resource</string>
</resources>

Loading…
Cancel
Save