Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I eventually found a way of doing this, but it isn't pretty. You can load the page in javascript via an XMLHttpRequest, which lets you access the status code. This probably messes up the progress notifications and may have other undesirable behaviour too. But it was acceptable in my app, so it may be of some help to others.</p> <pre><code>public class StatusNotifyingWebView extends WebView { public interface OnStatusReceivedListener { void onStatusReceived(int statusCode); } private class JsInterface { public void notifyRequestStatus(final int statusCode) { getHandler().post(new Runnable() { @Override public void run() { mOnStatusReceivedListener.onStatusReceived(statusCode); } }); } } private OnStatusReceivedListener mOnStatusReceivedListener; public void setOnStatusReceivedListener(final OnStatusReceivedListener listener) { mOnStatusReceivedListener = listener; addJavascriptInterface(new JsInterface(), "statusNotifyJsInterface"); } public void loadUrlWithStatusEvent(final String url) { Assert.assertNotNull(mOnStatusReceivedListener); final String script = " var httpRequest = new XMLHttpRequest();\n" + "httpRequest.open('GET', '" + url + "', false);\n" + "try { httpRequest.send(null); } catch (err) { }\n" + "statusNotifyJsInterface.notifyRequestStatus(httpRequest.status);\n" + "document.write(httpRequest.responseText);\n" + "document.close();\n"; final String html = "&lt;html&gt;&lt;head&gt;&lt;script&gt;" + script + "&lt;/script&gt;&lt;/head&gt;&lt;body/&gt;&lt;/html&gt;"; loadDataWithBaseURL(url, html, "text/html", "UTF-8", null); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload