2

I was wondering what used to be used before setstatuscodeandReasonPhrase method was added for android api level 21 (lollipop), I am using an older version (kitkat) and planning to use this method or alternative and wondering how I can go about it? Any Clue? Thanks!

2 Answers2

2

There wasn't anything. It was not possible to communicate a status code to WebView from shouldInterceptRequest.

Mikhail Naganov
  • 6,643
  • 1
  • 26
  • 26
  • @JusticeBauer: I'm still not sure, what do you want to achieve by passing the status code to WebView. Even in the latest API, WebView will not follow a redirect if you return a 3xx code to it. And for all other codes, it will just display the page from the data you will provide. Moreover, it is not possible to retrieve a HTTP status code *from* WebView after loading has finished. – Mikhail Naganov Mar 19 '15 at 21:24
0

Well. Actually there is no way to set it in KitKat (or lower) versions. In my case I wanted to return a 200 status for lower lollipop versions. What I did was just add an empty(not null) InputStream to the WebResourceResponse constructor.

WebResourceResponse webResourceResponse = new WebResourceResponse("text/html", "UTF-8", new InputStream() {
    @Override
    public int read() throws IOException {
        return 0;
    }
});
febaisi
  • 644
  • 6
  • 15