2

I'm implementing a timeout based on this: set loadURLTImeOutValue on webview

When the time limit is reached, I hide the WebView and display an error. Sometimes, the time limit is reached when the page is being downloaded/rendered. I don't want the error to appear when the page is being downloaded. I only want the error to appear if there's a network issue or if the page can't be reached.

How do I check the current status of a WebView? (e.g. resolving DNS, waiting for server, downloading contents, etc)

Community
  • 1
  • 1
Leo Jiang
  • 24,497
  • 49
  • 154
  • 284

1 Answers1

0

You can check the loading status by WebChromeClient.onProgressChanged function.

boolean isLoading = false;

void initWebView(WebView webView) {
    webView.setWebChromeClient(new MyWebChromeClient());
}


class MyWebChromeClient extends WebChromeClient {
    public MyWebChromeClient() {

    }

    public void onProgressChanged(WebView view, int newProgress) {
        if (newProgress == 100) {
            isLoading = false;
        } else {
            isLoading = true;
        }

    }
}
UnknownStack
  • 1,350
  • 16
  • 18