Commit d3cd1707 by huangzhicong

完善webview的设置

parent e7cc5313
...@@ -2,6 +2,7 @@ package com.maxrocky.nativeview.fragment ...@@ -2,6 +2,7 @@ package com.maxrocky.nativeview.fragment
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.net.Uri import android.net.Uri
import android.net.http.SslError
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
...@@ -70,6 +71,16 @@ class MainFragment : Fragment() { ...@@ -70,6 +71,16 @@ class MainFragment : Fragment() {
message: String?, message: String?,
result: JsResult? result: JsResult?
): Boolean = false ): Boolean = false
override fun onConsoleMessage(message: String?, lineNumber: Int, sourceID: String?) {
super.onConsoleMessage(message, lineNumber, sourceID)
Log.d(TAG, "onConsoleMessage: $message\nlineNumber: $lineNumber\nsourceID: $sourceID")
}
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
Log.d(TAG, "onConsoleMessage: ${consoleMessage?.message()}\nmessageLevel: ${consoleMessage?.messageLevel()}\nlineNumber: ${consoleMessage?.lineNumber()}\nsourceID: ${consoleMessage?.sourceId()}")
return super.onConsoleMessage(consoleMessage)
}
} }
wv.webViewClient = object : WebViewClient() { wv.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
...@@ -84,9 +95,26 @@ class MainFragment : Fragment() { ...@@ -84,9 +95,26 @@ class MainFragment : Fragment() {
Log.d(TAG, "shouldOverrideUrlLoading new: ${request?.url}") Log.d(TAG, "shouldOverrideUrlLoading new: ${request?.url}")
return super.shouldOverrideUrlLoading(view, request) return super.shouldOverrideUrlLoading(view, request)
} }
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
handler?.proceed()
}
} }
wv.settings.apply { wv.settings.apply {
javaScriptEnabled = true javaScriptEnabled = true
javaScriptCanOpenWindowsAutomatically = true
cacheMode = WebSettings.LOAD_NO_CACHE
domStorageEnabled = true
databaseEnabled = true
allowFileAccess = true
setSupportZoom(true)
builtInZoomControls = true
layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL
useWideViewPort = true
} }
wv.addJavascriptInterface(WebInterface(), "maxrocky") wv.addJavascriptInterface(WebInterface(), "maxrocky")
var url = arguments?.getString(ARG_URL) var url = arguments?.getString(ARG_URL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment