简体   繁体   中英

Getting blank page in Android WebViewClient

I am trying open twitter link : http://mobile.twitter.com/pawan_rathore88 in my activity. If I set WebViewClient to webview I am getting blank page. But when I load url without setting any webviewclient, it loads page properly. 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

After tweaking the code around, it seems to be a user agent problem, seems that changing it to a desktop useragent fixes this problem :

  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. I think the problem is not well perform user string agent. But cannot find it out now.

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

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