问题
WebViewClient.onReceivedError
was deprecated, now I have to use onReceivedHttpError
to handle the webview errors, however this method receives the error from any resource, which is not what I desire.
I wish only to detect the main URL failing.
How should I detect the error if I am using API 10?
I tried using the request.getUrl()
method but it is only compatible with API 23.
回答1:
Meanwhile, I ended up doing this:
@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)
}
}
}
来源:https://stackoverflow.com/questions/43664260/android-webviewclient-onreceivedhttperror-determine-if-is-main-resource