WebViewClient onReceivedError 已弃用,新版本未检测到所有错误 [英] WebViewClient onReceivedError deprecated, new version does not detect all errors

查看:26
本文介绍了WebViewClient onReceivedError 已弃用,新版本未检测到所有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android SDK 23 中 onReceivedError(WebView view, int errorCode, String description, String failedUrl) 已被弃用并替换为 onReceivedError(WebView view, WebResourceRequest request, WebResourceError error).但是,如果我将手机置于飞行模式并在 WebView 上加载 url,则只会调用该方法的弃用版本.

In the Android SDK 23 onReceivedError(WebView view, int errorCode, String description, String failingUrl) has been deprecated and replaced with onReceivedError(WebView view, WebResourceRequest request, WebResourceError error). However if I put my phone in Airplane mode and load an url on my WebView, only the deprecated version of the method is called.

onReceivedHttpError (WebView view, WebResourceRequest request, WebResourceResponse errorResponse) 也没有用,因为它只检测高于 500 的错误,而我得到的是 109 状态代码.

onReceivedHttpError (WebView view, WebResourceRequest request, WebResourceResponse errorResponse) is also not useful, as it only detects errors higher than 500, and I am getting a 109 status code.

是否有一种非弃用的方法来检测我的 WebView 加载失败?

Is there a non-deprecated way of detecting that my WebView failed to load?

推荐答案

请注意,您正在测试的移动设备需要实际运行 Android Marshmallow (API 23).即使您在 API 23 SDK 上开发您的应用程序,然后在 Android Lollipop 上运行该应用程序,您仍然会得到旧的"onReceivedError,因为这是操作系统的功能,而不是 SDK 的功能.

Please note that the mobile device where you are testing needs to actually run Android Marshmallow (API 23). Even if you develop your app on API 23 SDK, but then run the app on Android Lollipop, you will still be getting the "old" onReceivedError, because it's the feature of the OS, not of an SDK.

此外,错误代码 109"(我猜这是 net::ERR_ADDRESS_UNREACHABLE)不是 HTTP 错误代码,而是 Chrome 的错误代码.onReceivedHttpError 仅针对通过 HTTP 从服务器收到的错误调用.当设备处于飞行模式时,它不可能收到来自服务器的回复.

Also, the "error code 109" (I guess, this is net::ERR_ADDRESS_UNREACHABLE) is not an HTTP error code, it's Chrome's error code. onReceivedHttpError is only called for the errors received from the server via HTTP. When the device is in airplane mode, it can't possibly receive a reply from a server.

这篇关于WebViewClient onReceivedError 已弃用,新版本未检测到所有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆