简体   繁体   中英

How to understand when a WebView finished loading a resource?

When I'm loading a resource in a WebView, in Android, I simply call the typical mWebView.loadUrl(ht); .

The problem is that I would like to check the final url, and to perform some operation, when all the redirects are finished to be followed.

I mean: if I load example.com/page1 , and this returns a 302 code that leads to another page (let's say, /page2 ), and this leads me again via a 302 redirection to another page ( /page3 ), and this finally gives me a 200 and stops there, I would like to know when this happens.

It looks like I don't have the possibility to check the response code, nor the headers, and onPageFinished as well as shouldOverrideUrl are called for each redirect. It's kinda like "stateless"...

How can I distinguish between a typical 302 redirect, and the actual end of the loading process (200)?

May be setting custom WebViewClient could help you:

 webView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {

            }
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM