[英]android event when url can't be opened because no internet connection
I am properly checking if device has internet connection or not but for any other reasons is not suitable for me. 我正在正确检查设备是否可以连接互联网,但由于任何其他原因不适合我。 I need to capture event when a webview tries to open a webpage but this one could not be opened due to internet conection.
当一个Webview试图打开一个网页时,我需要捕获事件,但是由于Internet连接而无法打开该网页。 Now, webview displays standard browser page "www.mypage.com could not be opened...".
现在,webview显示标准浏览器页面“ www.mypage.com无法打开...”。 Which event can be handled for this?
可以处理哪个事件? Thank you
谢谢
尝试使用附加到WebView的WebViewClient拦截事件。
I generally check what response the req sent to internet connection gives and if it fails I throw a customised Exception
.And in my catch
block I handle it the way I want like give customised message, alert
or Toast
. 我通常检查发送到Internet连接的请求所给出的响应,如果失败,则抛出自定义的
Exception
。在catch
块中,我以自己想要的方式进行处理,例如给出自定义的消息, alert
或Toast
。
The conditions I check for which url can't be opened: 我检查无法打开哪个网址的条件:
Each of them I handle differently using my own exception classes. 他们每个人都使用自己的异常类以不同的方式处理。
You should be getting connection timeout response of sort. 您应该得到某种连接超时响应。 Normally, webview would display default result but you can create your own handler to manage it.
通常,webview将显示默认结果,但是您可以创建自己的处理程序来对其进行管理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.