I HttpsUrlConnection
connection to the shouldInterceptRequest
method in the WebViewClient
class. But as deducted in the version of Android 4.4 there is an IO lock. How can you get around it? And then the execution of the HttpsUrlConnection
is aborted as soon as I try to get an InputStream
. And if you just execute this query using new Thread(new Runnable(){...}).start();
everything will work fine.
@Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { try { HttpsURLConnection urlConnection = getHttpsConnection(url, false); Log.d("logba", "A -> getData : status=" + urlConnection.getResponseCode()); InputStream stream = urlConnection.getInputStream(); Log.d("logba", "A -> getData : stream=" + stream); return new WebResourceResponse("text/html", "utf-8", stream); } catch (IOException ignored) { } return null; } private HttpsURLConnection getHttpsConnection(String url, boolean isPost) throws IOException { URL urlConnection = new URL(url); HttpsURLConnection httpsURLConnection = (HttpsURLConnection) urlConnection.openConnection(); //httpsURLConnection.setSSLSocketFactory(sslSocketFactory); httpsURLConnection.setInstanceFollowRedirects(false); httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(isPost); httpsURLConnection.setUseCaches(true); httpsURLConnection.setReadTimeout(60_000); httpsURLConnection.setConnectTimeout(60_000); httpsURLConnection.setRequestMethod(isPost ? POST : GET); return httpsURLConnection; }