0

I have a WebView which loads a URL all well & good. I have gotten a WebViewClient and extended onProgressChanged, but as far as I can tell it is not being called. Any ideas?

 wv.setWebViewClient(new WebViewClient(){

        public void onProgressChanged(final WebView view, final int newProgress) {
            Log.e("APPNAME", String.valueOf(newProgress));
            if (newProgress < 100 && progressBar.getVisibility() == ProgressBar.GONE){
                progressBar.setVisibility(ProgressBar.VISIBLE);
            }
            progressBar.setProgress(newProgress);
            progressTxt.setText(newProgress);
            if (newProgress == 100){
                progressBar.setVisibility(ProgressBar.GONE);
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
             InputStream is = null;
             byte[] buffer = null;
                try {
                    is = getAssets().open("error.html");
                    int size = 0;
                    size = is.available();
                    buffer = new byte[size];
                    is.read(buffer);
                    is.close();
                }
                catch(Exception e){

                }
                String str = new String(buffer);
                str = str.replace("%@", description);

                view.loadDataWithBaseURL("file:///android_asset/", str, "text/html", "utf-8", null); 
        }
    });
SquiresSquire
  • 2,404
  • 4
  • 23
  • 39

3 Answers3

9

Try this

You are using wrong webClient

wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int newProgress) {
                progressBar.setProgress(newProgress);
            }
        });
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
2

WebView client does not have any method called onProgressChanged. You can check it here

Move your code into webchrome client which supports this method. Check here

Shrikant
  • 1,560
  • 1
  • 15
  • 32
0

use webChromeClient instead of webViewClient

  • 1
    Please, can you extend your answer with more detailed explanation? This will be very useful for understanding. Thank you! – vezunchik Apr 07 '19 at 07:52