Вопрос

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); 
        }
    });
Это было полезно?

Решение

Try this

You are using wrong webClient

wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int newProgress) {
                progressBar.setProgress(newProgress);
            }
        });

Другие советы

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

use webChromeClient instead of webViewClient

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top