Group Group Group Group Group Group Group Group Group

How to increase response read timeout in GeckoView for Android

I am having an issue sometimes on slow connections. If the connection is slow then the attempt to load a web-page might cause a screen like this one:

I understand is that the default response read timeout is set by default to 39 seconds. My question, how to increase that in code?

Any help guys? There must be a way to di it.

In my example, two timeouts are set. The connection timeout throws java.net.SocketTimeoutException: Socket is not connected and the socket timeout java.net.SocketTimeoutException: The operation timed out.

HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
If you want to set the Parameters of any existing HTTPClient (e.g. DefaultHttpClient or AndroidHttpClient) you can use the function setParams().

httpClient.setParams(httpParameters);

1 Like

But how to use this with GeckoView for Android?

We can use onLoadResource method of WebViewClient instead of Timer. Like this:

webView.setWebViewClient(new WebViewClient() {

@Override 
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return false;
}

@Override 
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    progressDialog.show();
}

@Override
public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    Log.d("WEBCLIENT", "onPageFinished");
}

@Override 
public void onLoadResource(WebView view, String url) {
    super.onLoadResource(view, url);
    Log.d("WEBCLIENT","onLoadResource");

    if(webView.getProgress() == 100) {
        progressDialog.dismiss();
    }    
}

}

Admin
Apps4Rent