Fix external links

This commit is contained in:
koalasat
2025-07-24 16:12:26 +02:00
parent e951f8bb15
commit d0276a232e

View File

@ -19,6 +19,8 @@ import android.webkit.WebSettings
import android.webkit.WebStorage
import android.webkit.WebView
import android.webkit.WebViewClient
import android.content.Intent
import android.net.Uri
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
@ -186,6 +188,38 @@ class MainActivity : AppCompatActivity() {
runOnUiThread {
updateStatus("Secure connection established. Loading app...")
// Set up WebViewClient that allows external links and deep links to be opened
webView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
val url = request.url.toString()
val uri = request.url
if (url.startsWith("file:///android_asset/")) return false
try {
Log.d("ExternalLink", "Attempting to open: $url")
val intent = Intent(Intent.ACTION_VIEW, uri)
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
Log.d("ExternalLink", "Successfully opened link in external app")
} else {
Log.w("ExternalLink", "No app found to handle: $url")
if (url.startsWith("http://") || url.startsWith("https://")) {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(browserIntent)
Log.d("ExternalLink", "Opened http/https link in browser")
}
}
return true
} catch (e: Exception) {
Log.e("ExternalLink", "Failed to open external link: ${e.message}", e)
return true
}
}
}
// Set up WebChromeClient with restricted permissions
webView.webChromeClient = object : WebChromeClient() {
override fun onGeolocationPermissionsShowPrompt(