4

I've got a WebView, with a WebViewClient that defines onErrorReceived, and onPageFinished.

The onPageFinished gets called correctly, so I know that the WebViewclient is attached to the WebView correctly. However, there's some javascript in the WebView that calls:

location.href="http://kernel.org/asdf/asdf/asdf/asdf";

And the onErrorReceived listener is not called, even though it's a 404. Does it not work with javascript calls?

Edit: After some testing, I have found that NO 404s are reported to this function whatsoever. I have a test project set up here: http://vimtips.org/media/WebViewTest.zip

It appears that this method cannot be used to test for 404s. Anyone know of a way to do this?

synic
  • 26,359
  • 20
  • 111
  • 149
  • It can't be done with WebView, you can however use the basic HTTPClient and check for the response code. Here is a link on how to do that: http://stackoverflow.com/questions/2592843/android-how-get-the-status-code-of-an-httpclient-request – Machine Feb 02 '12 at 17:40

2 Answers2

2

In following situation, onErrorReceived will be called.

  • ERROR_AUTHENTICATION User authentication failed on server
  • ERROR_BAD_URL Malformed URL
  • ERROR_CONNECT Failed to connect to the server
  • ERROR_FAILED_SSL_HANDSHAKE Failed to perform SSL handshake
  • ERROR_FILE Generic file error
  • ERROR_FILE_NOT_FOUND File not found
  • ERROR_HOST_LOOKUP Server or proxy hostname lookup failed
  • ERROR_IO Failed to read or write to the server
  • ERROR_PROXY_AUTHENTICATION User authentication failed on proxy
  • ERROR_REDIRECT_LOOP Too many redirects
  • ERROR_TIMEOUT Connection timed out
  • ERROR_TOO_MANY_REQUESTS Too many requests during this load
  • ERROR_UNKNOWN Generic error
  • ERROR_UNSUPPORTED_AUTH_SCHEME Unsupported authentication scheme (not basic or digest)
  • ERROR_UNSUPPORTED_SCHEME Unsupported URI scheme

Actually, none of HTTP response codes are in the list above.

York
  • 503
  • 3
  • 23
1

It can't be done. At least, not in a non-hacky way.

synic
  • 26,359
  • 20
  • 111
  • 149