-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Description
package com.tauri.test
import android.content.Context
import android.content.DialogInterface
import android.view.KeyEvent
import android.view.ViewGroup
import android.webkit.CookieManager
import android.webkit.JsResult
import android.webkit.WebChromeClient
import android.webkit.WebView
import androidx.appcompat.app.AlertDialog
class MainActivity : TauriActivity() {
override fun onWebViewCreate(webView: WebView) {
webView.webChromeClient = customWebChromeClient
// webView.webChromeClient = CustomWebChromeClient(this)
super.onWebViewCreate(webView)
}
private val customWebChromeClient: WebChromeClient = object : WebChromeClient() {
override fun onJsAlert(
webview: WebView,
url: String,
message: String,
result: JsResult
): Boolean {
AlertDialog.Builder(this@MainActivity).setTitle(R.string.app_name)
.setMessage(message)
.setPositiveButton(
"OK"
) { _: DialogInterface?, _: Int -> result.confirm() }
.setCancelable(false)
.show()
return true
}
}
}
class CustomWebChromeClient(private val context: Context) : WebChromeClient() {
override fun onJsAlert(
webview: WebView,
url: String,
message: String,
result: JsResult
): Boolean {
AlertDialog.Builder(context).setTitle(R.string.app_name)
.setMessage(message)
.setPositiveButton(
"ok"
) { _: DialogInterface?, _: Int -> result.confirm() }
.setCancelable(false)
.show()
return true
}
}I would be truly grateful for your expert advice. As someone with limited professional knowledge, I often struggle to translate theory into practice. Any insights to help me bridge this gap would be invaluable. Thank you so much for your time and wisdom!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels