From 099c448bc6d6b85634faae20faaa44e6caba7910 Mon Sep 17 00:00:00 2001 From: dimitris Date: Fri, 5 Jun 2026 21:21:19 +0200 Subject: [PATCH] Open external links outside the game WebView --- .../alexbarry/alexgames/LocalClientWebView.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/android/app/src/main/java/net/alexbarry/alexgames/LocalClientWebView.kt b/src/android/app/src/main/java/net/alexbarry/alexgames/LocalClientWebView.kt index 20897f5..19cc0b5 100644 --- a/src/android/app/src/main/java/net/alexbarry/alexgames/LocalClientWebView.kt +++ b/src/android/app/src/main/java/net/alexbarry/alexgames/LocalClientWebView.kt @@ -1,6 +1,8 @@ package net.alexbarry.alexgames import android.annotation.SuppressLint +import android.content.ActivityNotFoundException +import android.content.Intent import android.net.Uri import android.os.Bundle import android.util.Log @@ -70,6 +72,25 @@ class LocalClientWebView : Fragment() { webview.evaluateJavascript("set_header_visible(false);", null); } + override fun shouldOverrideUrlLoading( + view: WebView?, + request: WebResourceRequest? + ): Boolean { + val uri = request?.url ?: return false + // The game is served from the local asset host. Send any + // other link out to the system so it opens in a browser + // instead of loading over the game. + if (uri.host == "appassets.androidplatform.net") { + return false + } + return try { + view?.context?.startActivity(Intent(Intent.ACTION_VIEW, uri)) + true + } catch (e: ActivityNotFoundException) { + false + } + } + override fun shouldInterceptRequest( view: WebView?, request: WebResourceRequest?