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
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.
There are several reasons why you might be getting an HTTP 404 code: One typical trigger for an error 404 message is when the page has been deleted from the website. The page was moved to another URL and the redirection was done incorrectly. You entered an incorrect URL address.
404 is a status code that tells a web user that a requested page is not available. 404 and other response status codes are part of the web's Hypertext Transfer Protocol response codes. The 404 code means that a server could not find a client-requested webpage.
Starting SDK 23 (Android M) you can use onReceivedHttpError
method to catch 404 and other HTTP errors. Just override inside your WebViewClient
@Override public void onReceivedHttpError (WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { Toast.makeText(view.getContext(), "HTTP error "+errorResponse.getStatusCode(), Toast.LENGTH_LONG).show(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With