From df2a1d545b7fdfef257bf48a8abe3f6c5eee10cf Mon Sep 17 00:00:00 2001 From: Simon Marquis Date: Sun, 10 Dec 2023 13:35:42 +0100 Subject: [PATCH] Handle `ActivityNotFoundException` when launching Chrome custom tab Fixes #1068 --- .../google/samples/apps/nowinandroid/core/ui/NewsFeed.kt | 8 +++++++- core/ui/src/main/res/values/strings.xml | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/ui/src/main/kotlin/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt b/core/ui/src/main/kotlin/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt index afdb584a2..a93276e87 100644 --- a/core/ui/src/main/kotlin/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt +++ b/core/ui/src/main/kotlin/com/google/samples/apps/nowinandroid/core/ui/NewsFeed.kt @@ -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() + } } /** diff --git a/core/ui/src/main/res/values/strings.xml b/core/ui/src/main/res/values/strings.xml index 65a855fc9..c593a608a 100644 --- a/core/ui/src/main/res/values/strings.xml +++ b/core/ui/src/main/res/values/strings.xml @@ -26,4 +26,6 @@ %1$s is followed %1$s is not followed + + Please install a browser to open this news resource