shouldOverrideUrlLoading在web视图为Android没有运行 [英] shouldOverrideUrlLoading in WebView for Android not running

查看:1151
本文介绍了shouldOverrideUrlLoading在web视图为Android没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- 编辑:发现 - 解决方案
想通了一些沉重的搜索之后 - 一个人(我字面上的意思是一个)表示,他们不是用的onPageLoad();它完美地工作,我的目的。不同的是,的onPageLoad()之后的运行速度比shouldOverrideUrlLoading,但它不会让我的code的差异。

- Solution Found-
Figured it out after some heavy searching - one person (I literally mean one) said they instead used onPageLoad(); which worked perfectly for my purposes. The difference is that onPageLoad() runs later than shouldOverrideUrlLoading, but It doesn't make a difference in my code.

我试图建立Twitter的授权使用OAuth认证的Andr​​oid应用程序,因此到目前为止,我可以成功地向用户发送到授权的URL,不过,我想现在要做的就是拦截重定向到一个回调(这只会导致404错误,我们的回调URL是不会对我们的服务器关联的页面)。我正在试图做的是检查URL是回调,然后从URL中提取的OAuth验证。我安装我的WebView与此code:

I'm trying to set up Twitter authorization with OAuth for an Android app, and thus far I can successfully send the user to the authorization URL, however, what I am trying to do now is intercept the redirect to the callback (which would just lead to a 404 error, our callback URL isn't going to have an associated page on our servers). What I'm attempting to do is check if the URL is our callback, then extract the OAuth Verifier from the URL. I setup my WebView with this code:

view = (WebView)findViewById(R.id.twitterWbVw);
view.setWebViewClient(new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView wView, String url)
    {
        String urlHolder;
        String[] verifExtrctr;
        urlHolder = url.substring(0, url.indexOf('?'));
        System.out.println("url");
        if(urlHolder.equalsIgnoreCase(CALLBACK_URL))
        {
            verifExtrctr = urlHolder.split("?");
            verifExtrctr = verifExtrctr[2].split("=");
            if(verifExtrctr[0].equalsIgnoreCase("oauth_verifier"))
            {
                params[5] = verifExtrctr[1];
                return true;
            }
            else
            {
                System.out.println("Inocorrect callback URL format.");
            }
        }
        else    
        {
            wView.loadUrl(url);
        }
        return true;
    }
});
view.loadUrl(urlAuthorize.toExternalForm());

事情是的甚至的System.out.println(URL);!的(这我使用到调试)的不执行的所以我pretty的多干的想法,并不能找到任何一个有类似的问题。授权URL经过细,我可以成功授权出于某种原因从未得到的拦截应用程序,但是重定向到一个回调URL。任何帮助将是AP preciated,这是我的onResume(),如果该事项。

Thing is even System.out.println("url");(which I'm using to debug)doesn't run! So I'm pretty much dry on ideas, and can't find anyone with a similar problem. The authorization URL goes through fine, and I can successfully authorize the app, however the redirect to the callback URL for some reason never get's intercepted. Any help would be appreciated, this is in my onResume() if that matters.

推荐答案

经过一番研究,我的结论是,尽管大多数的教程在那里说, shouldOverrideUrlLoading()做被调用时:

After some research I conclude that despite what most of the tutorials out there say, shouldOverrideUrlLoading() does not get called when:

  1. 您加载像

  1. You load a URL like

loadUrl("http://www.google.com");

  • 浏览器通过HTTP重定向自动将用户重定向。

  • The browser redirects the user automatically via an HTTP Redirect.

    但它确实的,得到你的时候,你点击的WebView内部网页中的链接调用。 IIRC Twitter的授权使用HTTP重定向..长号,这将是有益的,如果它的工作全部教程怎么说它。我觉得这是一个很老版本的Andr​​oid API ...

    It does however, get called when you you click on a link inside a webpage inside the webview. IIRC the twitter authorization uses an HTTP Redirect.. Bummer, this would be helpful if it worked how all the tutorials say it does. I think this is from a very old version the Android API...

    您可能要考虑覆盖的 WebChromeClient 喜欢这里的 onProgressChanged 方法:<一href="http://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url-in-android">How听一个web视图加载完成在Android中的URL? onPageFinished()方法 WebViewClient

    You might want to consider overriding the onProgressChanged method of a WebChromeClient like here: How to listen for a Webview finishing loading a URL in Android? or the onPageFinished() method of the WebViewClient.

    这篇关于shouldOverrideUrlLoading在web视图为Android没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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