我正在尝试在Webview中加载本地文件,并且工作正常,但我注意到未调用自定义WebViewClient。但是,当我将其更改为https://google.com时,将调用WebViewClient。我检查onLoadResource方法。我想以某种方式覆盖它。有帮助吗?
@SuppressLint("JavascriptInterface")
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
rootView = inflater.inflate(R.layout.activity_webview_video_layout, container, false)
ScreenTracking.getInstance().enterScreen(TAG_WEBACTIVITY_FRAG)
val webView = rootView!!.findViewById<WebView>(R.id.actWebVideoView)
webView.webChromeClient = WebChromeClient()
webView.settings.javaScriptEnabled = true
webView.settings.domStorageEnabled = true
webView.settings.allowUniversalAccessFromFileURLs = true
webView.settings.mediaPlaybackRequiresUserGesture = false
webView.webViewClient = MyWebViewClient()
webView.settings.allowFileAccessFromFileURLs = true
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
if (videoFragmentCallback != null) {
videoFragmentCallback!!.setWV(webView, jsInterface!!)
}
// webView.loadUrl("https://google.com")
webView.loadUrl("file:///android_asset/www/baashtml.html")
webView.addJavascriptInterface( jsInterface, "Android")
return rootView
}
private inner class MyWebViewClient : WebViewClient() {
override fun onLoadResource(view: WebView?, url: String?) {
println( "onLoadResource $url")
super.onLoadResource(view, url)
}
@TargetApi(Build.VERSION_CODES.N)
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
println("overrideURL ${request.url} book" )
view.loadUrl(request.url.toString())
return true
}
}