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

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

问题描述

我的Web视图加载一个URL,该URL在完成加载后将更改为另一个URL. 如何捕获新的网址. getURL()始终返回第一个网址,而不是第二个. 如果我使用浏览器,则可以看到新的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 来拦截所有网址 在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天全站免登陆