gpt4 book ai didi

webview - Webview shouldInterceptRequest方法始终返回null

转载 作者:行者123 更新时间:2023-12-02 13:37:35 27 4
gpt4 key购买 nike

Webview shouldInterceptRequest方法总是返回null。我去了adblocking的use方法。我尝试了很多adblock方法,但是总是需要这个shouldInterceptRequest方法,但是它返回null。

我的网页 View 代码

webView.webViewClient = object : WebViewClient() {

override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {




view!!.loadUrl(request!!.url.toString())
return true


}

override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest?): WebResourceResponse {
return if (

AdBlocker.isAd(request!!.url.toString()))
AdBlocker.createEmptyResource()
else
super.shouldInterceptRequest(view, request)
}



override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
eTadres.setText(url)


suankiurl= url!!
super.onPageStarted(view, url, favicon)
}



override fun onLoadResource(view: WebView?, url: String?) {
if (webView.visibility==View.GONE){webView.visibility=View.VISIBLE}
super.onLoadResource(view, url)
}


}

错误记录
W/System.err: java.lang.IllegalStateException: super.shouldInterceptRequest(view, request) must not be null
10-19 17:46:53.185 306-349/com.bulamac.tarayicibulamac W/System.err: at com.bulamac.tarayicibulamac.WebviewFragment$onCreateView$5.shouldInterceptRequest(WebviewFragment.kt:182)
10-19 17:46:53.185 306-349/com.bulamac.tarayicibulamac W/System.err: at com.android.webview.chromium.WebViewContentsClientAdapter.shouldInterceptRequest(WebViewContentsClientAdapter.java:52)
10-19 17:46:53.185 306-349/com.bulamac.tarayicibulamac W/System.err: at org.chromium.android_webview.AwContents$BackgroundThreadClientImpl.shouldInterceptRequest(AwContents.java:9)
10-19 17:46:53.185 306-349/com.bulamac.tarayicibulamac W/System.err: at org.chromium.android_webview.AwContentsBackgroundThreadClient.shouldInterceptRequestFromNative(AwContentsBackgroundThreadClient.java:11)
10-19 17:46:53.186 306-349/com.bulamac.tarayicibulamac A/chromium: [FATAL:jni_android.cc(243)] Please include Java exception stack in crash report

最佳答案

super.shouldInterceptRequest(view, request)将始终返回null(请参见此代码的实现)。如果要防止应用崩溃,则应使用以下示例

更改为“:WebResourceResponse?” ('?' 加入)

override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest?): WebResourceResponse? {
return super.shouldInterceptRequest(view, request)
}

关于webview - Webview shouldInterceptRequest方法始终返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52897625/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com