简体   繁体   中英

Android WebView client shouldOverrideUrlLoading() method is not getting called for redirect urls

I am trying to intercept the code from the redirect I get from Instagram Authentication. I'm using the shouldOverrideUrlLoading() to stop the page from loading, but the WebView goes ahead and loads it anyway. Here is my code

            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

            String url = view.getUrl();
            if (url.startsWith("https://someurl.com")){
                return true;
            }
            return false;

        }

Found out I was using the WebView URL instead of the URL from the WebResourceRequest, The following code String url = view.getUrl(); should look like this String url = String.valueOf(request.getUrl(); And the whole method will look like so:

        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

        String url = String.valueOf(request.getUrl();
        if (url.startsWith("https://someurl.com")){
            return true;
        }
        return false;

    }

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