Android, catch webview redirection 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.
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
}
});