Search code examples
androidwebviewandroid-webview

Android, catch webview redirection url


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.


Solution

  • 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
            }
        });