Android, Catch Webview Redirection Url
Solution 1:
You could use a webClient and implement shouldOverrideUrlLoading to intercept all the urls before the WebView loads them.
mWebView.setWebViewClient(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
// Here put your codeLog.d("My Webview", url);
// return true; //Indicates WebView to NOT load the url;returnfalse; //Allow WebView to load url
}
});
Solution 2:
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.
Solution 3:
In my case WebViewClient wasn't showing if there was changes on the webview, I supposed that is something about the web that is been running.
I could get that information from the WebChromeClient with OnProgressChanged, I don't know if this would help people anyway, but here is the code:
webview.webChromeClient = object : WebChromeClient(){
overridefunonProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress)
if (newProgress == 100) {
Log.d("testing", webview.getOriginalUrl())
Log.d("testing", webview.url)
}
}
}
This way I could know what is been loaded and when is finished.
Post a Comment for "Android, Catch Webview Redirection Url"