如何从Android的WebView功能检查,如果一个网页是一个"未发现404页"?是一个、功能、发现、网页

2023-09-13 00:22:28 作者:薄雪草少年?

我要检查404找不到网页从web视图,如果它是一个404,然后我恢复到 previous页面。泰对你有所帮助。

I want to check a "404 page not found" from a WebView and if it's a 404 then I revert to the previous page. Ty for your help

编辑也是我想看到的网页是纯.JPG 1.JPG 2.JPG 3.JPG,但我有一个如何存在许多图像没有资料。因此,如果任何人都可以提出另一种方法,欢迎他这样做。

EDIT also the webpages I want to see are pure .jpg 1.jpg 2.jpg 3.jpg but I have no info of how many images exist. So if anyone can propose another method, he is welcome to do so.

推荐答案

附加 WebViewClient 的WebView ,在这里您可以覆盖 onReceivedError()来了解404的响应 - 尽管这可能会被返回 ERROR_FILE_NOT_FOUND

Attach a WebViewClient to your WebView, where you override onReceivedError() to find out about the 404 response -- though that will probably be returned as ERROR_FILE_NOT_FOUND.