From 849d4e6e6258adf3097a21e9e4347a2acc21f587 Mon Sep 17 00:00:00 2001 From: dimitris Date: Sat, 16 May 2026 14:47:38 +0200 Subject: [PATCH] fix(webview): route non http(s) schemes out of WebPageView WebPageView's WebViewClient overrides shouldInterceptRequest, doUpdateVisitedHistory, onPageStarted and onPageFinished but does not override shouldOverrideUrlLoading. Any navigation the loaded supplier page hands the WebView (mailto: on a contact link, tel: on a phone number, intent: from a deep link) is dispatched by the default handler and stays inside the in-app browser. Override shouldOverrideUrlLoading to keep http(s) and about: schemes inside the WebView and route the rest via Intent.ACTION_VIEW, wrapping the launch in try/catch so a missing handler does not crash the Activity. --- .../java/com/codelv/inventory/MainActivity.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/java/com/codelv/inventory/MainActivity.kt b/app/src/main/java/com/codelv/inventory/MainActivity.kt index cc2a354..26e77bc 100644 --- a/app/src/main/java/com/codelv/inventory/MainActivity.kt +++ b/app/src/main/java/com/codelv/inventory/MainActivity.kt @@ -1,6 +1,7 @@ package com.codelv.inventory import android.annotation.SuppressLint +import android.content.ActivityNotFoundException import android.content.Intent import android.graphics.Bitmap import android.net.Uri @@ -1681,6 +1682,25 @@ fun WebPageView( ViewGroup.LayoutParams.MATCH_PARENT ) setWebViewClient(object : WebViewClient() { + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest? + ): Boolean { + val target = request?.url ?: return false + val scheme = target.scheme?.lowercase() + if (scheme == "http" || scheme == "https" || scheme == "about") return false + return try { + val intent = Intent(Intent.ACTION_VIEW, target).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + } + view?.context?.startActivity(intent) + true + } catch (e: ActivityNotFoundException) { + Log.w("webview", "No handler for $target", e) + true + } + } + // WARNING: This only appears to work for GET requests and does not block a majority of the garbage requests override fun shouldInterceptRequest( view: WebView,