Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/src/main/java/com/codelv/inventory/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down