From f6feb2cf8c6d656105e50f1765e7a623c9df856d Mon Sep 17 00:00:00 2001 From: johan12345 Date: Sat, 16 Dec 2023 15:23:55 +0100 Subject: [PATCH] fix crash when no browser is installed --- .../net/vonforst/evmap/navigation/CustomNavigator.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/vonforst/evmap/navigation/CustomNavigator.kt b/app/src/main/java/net/vonforst/evmap/navigation/CustomNavigator.kt index 7f56f503..60d9293b 100644 --- a/app/src/main/java/net/vonforst/evmap/navigation/CustomNavigator.kt +++ b/app/src/main/java/net/vonforst/evmap/navigation/CustomNavigator.kt @@ -1,10 +1,12 @@ package net.vonforst.evmap.navigation import android.app.Activity +import android.content.ActivityNotFoundException import android.content.Context import android.net.Uri import android.os.Bundle import android.util.AttributeSet +import android.widget.Toast import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent import androidx.core.content.ContextCompat @@ -52,7 +54,15 @@ class CustomNavigator( .build() ) .build() - intent.launchUrl(context, Uri.parse(url)) + try { + intent.launchUrl(context, Uri.parse(url)) + } catch (e: ActivityNotFoundException) { + Toast.makeText( + context, + R.string.no_browser_app_found, + Toast.LENGTH_SHORT + ).show() + } } override fun popBackStack() = true // Managed by Chrome Custom Tabs