From 5a11fb6d0fb8ff1776c070b035339ddcdf96a812 Mon Sep 17 00:00:00 2001 From: dimitris Date: Fri, 15 May 2026 11:38:57 +0200 Subject: [PATCH] fix(webview): guard external link launch in WebFragment with try/catch shouldOverrideUrlLoading sent every non-meteocool URL to startActivity(Intent.ACTION_VIEW) without protection. If the device has no app that can handle the URL (no browser/viewer for the scheme, custom intents like mailto with no mail client, etc.) it raises ActivityNotFoundException and crashes the map fragment. Wrap the launch in try/catch and fall back to a short Toast so the fragment keeps working. --- app/src/main/java/com/meteocool/ui/map/WebFragment.kt | 8 ++++++-- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/meteocool/ui/map/WebFragment.kt b/app/src/main/java/com/meteocool/ui/map/WebFragment.kt index 084e23e..e7c4125 100644 --- a/app/src/main/java/com/meteocool/ui/map/WebFragment.kt +++ b/app/src/main/java/com/meteocool/ui/map/WebFragment.kt @@ -1,8 +1,10 @@ package com.meteocool.ui.map import android.Manifest +import android.content.ActivityNotFoundException import android.content.Intent import android.content.pm.PackageManager +import android.widget.Toast import android.content.res.Configuration import android.net.Uri import android.os.Bundle @@ -289,8 +291,10 @@ class WebFragment : Fragment() { return false } // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs - Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply { - startActivity(this) + try { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url))) + } catch (e: ActivityNotFoundException) { + Toast.makeText(requireContext(), R.string.cant_open_link, Toast.LENGTH_SHORT).show() } return true } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd19756..6bca518 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -81,4 +81,6 @@ notifications + No app found to open this link +