简体   繁体   English

在Android WebViewClient中获取空白页面

[英]Getting blank page in Android WebViewClient

I am trying open twitter link : http://mobile.twitter.com/pawan_rathore88 in my activity. 我正在尝试打开twitter链接: http//mobile.twitter.com/pawan_rathore88在我的活动中。 If I set WebViewClient to webview I am getting blank page. 如果我将WebViewClient设置为webview,我将获得空白页面。 But when I load url without setting any webviewclient, it loads page properly. 但是当我在没有设置任何webviewclient的情况下加载url时,它会正确加载页面。 Does anyone have idea what can be a problem. 有谁知道什么可能是一个问题。 Following is my code snippet. 以下是我的代码段。

webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
//if I comment the following line then webpage loads properly in default Android browser.
webview.setWebViewClient(new WebViewClient() {
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                 Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
               }
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

    Log.v(tag, "url :" + url);
    view.loadUrl(url);
    return true;
        }
 });
    webview.loadUrl("http://mobile.twitter.com/pawan_rathore88");

Thanks, Pawan 谢谢,Pawan

After tweaking the code around, it seems to be a user agent problem, seems that changing it to a desktop useragent fixes this problem : 调整代码后,它似乎是一个用户代理问题,似乎将其更改为桌面useragent修复此问题:

  WebView web = (WebView)findViewById(R.id.webView1);
        web.getSettings().setUserAgentString("Mozilla/5.0 (Macintosh; " +
            "U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, " +
            "like Gecko) Version/5.0 Safari/533.16");

        String url = "http://mobile.twitter.com/pawan_rathore88";
        web.loadUrl(url);

That is exact my problem too. 这也是我的问题。 Load Desktop version very good but not mobile version. 加载桌面版本非常好但不是移动版本。 If running on default browser, then Mobile version normally run. 如果在默认浏览器上运行,则通常运行Mobile版本。 I think the problem is not well perform user string agent. 我认为问题不是很好地执行用户字符串代理。 But cannot find it out now. 但现在找不到它。

这是目前Twitter的问题,并且在所有Web工具包移动浏览器中都失败了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM