Android - Webviewclient onReceivedHttpError 判断是否是主要资源
Android - Webviewclient onReceivedHttpError determine if is main resource
WebViewClient.onReceivedError
已被弃用,现在我必须使用 onReceivedHttpError
来处理 webview 错误,但是此方法从任何资源接收错误,这不是我想要的。
我只想检测 main URL 失败。
如果我使用API 10,我应该如何检测错误?
我尝试使用 request.getUrl()
方法,但它只与 API 23.
兼容
与此同时,我最终这样做了:
@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)
}
}
}
WebViewClient.onReceivedError
已被弃用,现在我必须使用 onReceivedHttpError
来处理 webview 错误,但是此方法从任何资源接收错误,这不是我想要的。
我只想检测 main URL 失败。
如果我使用API 10,我应该如何检测错误?
我尝试使用 request.getUrl()
方法,但它只与 API 23.
与此同时,我最终这样做了:
@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)
}
}
}