WebViewClient.onReceivedError
已被弃用,现在我必须使用onReceivedHttpError
来处理webview错误,但是此方法会从任何资源收到错误,这不是我想要的。
我希望只检测主网址失败。
如果我使用的是 API 10 ,我该如何检测错误?
我尝试使用request.getUrl()
方法,但它只与API 23兼容。
答案 0 :(得分:2)
与此同时,我最终这样做了:
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//your thing (f.e. show error message)
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//url is the original loading url
if(request.getUrl().equals(url)) {
//your thing (f.e. show error message)
}
}
}