本文介绍了Android-WebviewClient onReceivedHttpError确定是否为主要资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
WebViewClient.onReceivedError
已过时,现在我必须使用onReceivedHttpError
来处理webview错误,但是此方法从任何资源接收到错误,这不是我想要的.
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.
我只希望检测到主网址失败.
如果我使用的是 API 10 ,我应该如何检测错误?
How should I detect the error if I am using API 10?
我尝试使用request.getUrl()
方法,但它仅与API 23兼容.
I tried using the request.getUrl()
method but it is only compatible with 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)
}
}
}
这篇关于Android-WebviewClient onReceivedHttpError确定是否为主要资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!