My web view loads a url that - after completing loading - gets changed to another url.
how can I catch the new url. getURL()
always returns the 1st url not the second.
I can see the new URL if i use a browser but I can't get if from the webview.
You could use a webClient and implement shouldOverrideUrlLoading to intercept all the urls before the WebView loads them.
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Here put your code
Log.d("My Webview", url);
// return true; //Indicates WebView to NOT load the url;
return false; //Allow WebView to load url
}
});
Use
getOriginalUrl ()
It returns the URL that was originally requested for the current page
getUrl ()
is not always the same as the URL passed to WebViewClient.onPageStarted
because although the load for that URL has begun, the current page may not have changed.
getOriginalUrl ()
gets the original URL for the current page. This is not always the same as the URL passed to WebViewClient.onPageStarted
because although the load for that URL has begun, the current page may not have changed. Also, there may have been redirects resulting in a different URL to that originally requested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With