Android,捕获 webview 重定向 url [英] Android, catch webview redirection url

查看:159
本文介绍了Android,捕获 webview 重定向 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络视图加载了一个 url,在完成加载后,该 url 被更改为另一个 url.我怎样才能捕捉到新的网址.getURL() 总是返回第一个 url 而不是第二个.如果我使用浏览器,我可以看到新的 URL,但如果从 webview 中看不到.

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.

推荐答案

您可以使用 webClient 并实现 shouldOverrideUrlLoading 来拦截所有 url在 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
        }
    });

这篇关于Android,捕获 webview 重定向 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆