From cad015f6ffd23716b9554c963c5814c55b9aab77 Mon Sep 17 00:00:00 2001 From: dimitris Date: Fri, 15 May 2026 20:39:10 +0200 Subject: [PATCH] fix(about): guard mailto / external-link launches with try/catch AboutActivity routes mailto: and http(s) links out of its WebView through startActivity. If the device has no app that can handle the intent (no mail client for mailto, no browser, a stripped-down build like an automotive head unit, etc.) startActivity raises ActivityNotFoundException and the About screen crashes mid-tap. Run the launch through a small helper that catches ActivityNotFoundException and shows a Toast so the activity stays alive. The happy path is unchanged. --- .../vectorcamera/AboutActivity.kt | 14 ++++++++++++-- app/src/main/res/values/strings.xml | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/dozingcatsoftware/vectorcamera/AboutActivity.kt b/app/src/main/java/com/dozingcatsoftware/vectorcamera/AboutActivity.kt index bab3102..56d7e22 100644 --- a/app/src/main/java/com/dozingcatsoftware/vectorcamera/AboutActivity.kt +++ b/app/src/main/java/com/dozingcatsoftware/vectorcamera/AboutActivity.kt @@ -1,11 +1,13 @@ package com.dozingcatsoftware.vectorcamera +import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle import android.webkit.WebView import android.webkit.WebViewClient +import android.widget.Toast import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import com.dozingcatsoftware.util.adjustPaddingForSystemUi @@ -42,11 +44,11 @@ class AboutActivity: AppCompatActivity() { override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { // Go to email for mailto: and default browser for http/https URLs. if (url.startsWith("mailto:")) { - startActivity(Intent(Intent.ACTION_SENDTO, Uri.parse(url))) + launchExternal(Intent(Intent.ACTION_SENDTO, Uri.parse(url))) return true } if (url.startsWith("http:") || url.startsWith("https:")) { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + launchExternal(Intent(Intent.ACTION_VIEW, Uri.parse(url))) return true } // Load file URLs in the same WebView. @@ -56,6 +58,14 @@ class AboutActivity: AppCompatActivity() { return super.shouldOverrideUrlLoading(view, url) } + private fun launchExternal(intent: Intent) { + try { + startActivity(intent) + } catch (e: ActivityNotFoundException) { + Toast.makeText(this@AboutActivity, R.string.no_app_to_open_link, Toast.LENGTH_SHORT).show() + } + } + // Selectively enable the back navigation callback depending on // whether it should do a "back" action in the browser. override fun doUpdateVisitedHistory(view: WebView?, url: String?, isReload: Boolean) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 555ce0e..b51990b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,7 @@ Vector Camera No pictures found. + No app available to open this link takePictureWithVolumeButton Take picture with volume button