Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm currently loading the URL in webview and everything works perfect. However, in poor network condition I'm getting Err: Timedout on webview with in 10 seconds. I would like to increase this time out value to lets say 60 seconds. Thank you in Advance. Here is my webview :

webView = findViewById(R.id.webview)
        webView?.let { webView ->
            webView.clearCache(true)
            webView.clearFormData()
            webView.clearHistory()
            Log.i(LOG_TAG,"cleared cache & history on webview")
            webView.settings.javaScriptEnabled = true;
            webView.settings.setAllowUniversalAccessFromFileURLs(true);
            webView.settings.allowContentAccess = true;
            webView.settings.domStorageEnabled = true;
            webView.webViewClient = MyWebViewClient(this, progressbarView, progressbar)

Here is my webview client code:

override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest?): Boolean { val url: String = request?.url.toString(); if (Global.isNetworkConnected(this@Orderdetailswebview)){ return checkAndProcessHolsterManagerCall(view, url) }else{ var networkDialog = NetworkErrorVideoFragment() networkDialog.show(fragmentManager, "NetworkErrorDialog") return true override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { return checkAndProcessHolsterManagerCall(view, url) override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? { if(fromActivityVal == "ViewTogether") { return super.shouldInterceptRequest(view, request) }else { return webResponse(request)

I think adding these two lines of code will solve your problem:

webView?.let { webView ->
    // Add these two lines of code
    webView.settings.setConnectTimeout(TIMEOUT_MILLIS)
    webView.settings.setReadTimeout(TIMEOUT_MILLIS)

Replace the value of TIMEOUT_MILLIS with the value you need

These properties don't seem to be available/accessible for android.webkit WebView & WebSettings. So this probably doesn't work or answer the question. developer.android.com/reference/android/webkit/WebSettings – neatchuck Nov 15, 2023 at 12:40

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.