2

I have a strange problem with my webview. I have a basic webview that I use to display webpages. This works the majority of the time, but there is one site in particular that does not render. I am not sure how to begin to debug this problem. Here is my initialization code for the webview:

    webView = (WebView) findViewById(R.id.rss_webView);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    });

    webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {

            pb.setProgress(progress);


            if (progress == 100)
                pb.setVisibility(View.GONE);
            else
                pb.setVisibility(View.VISIBLE);

        }


    });

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);

    webView.loadUrl(URL);

The URL that is having problems is: http://twitter.com/AdamSchefter/statuses/236553635608285184

This page (and other twitter pages) render as a blank gray square on the screen with no content.

I have noticed that if I open the url with my normal Android browser it gets redirected to a mobile version. The webview does not do this as far as I can tell. When setting breakpoints in the shouldOverrideUrlLoading() method, I don't receive any redirect urls.

I have scanned logcat for any indication of error. I don't think the webview performs any logging to log cat at all (other than a not that a webview was loaded) because there is nothing there.

I am not sure how to track down this issue. Any thoughts?

I have a lot of twitter sources that I need to display and I don't have control over the URL.

1 Answer 1

3

Ok done by adding below line in my code

webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U;`
Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like
Gecko) Version/4.0 Mobile Safari/530.17");

I got it from this post at stackoverflow Problems loading mobile.twitter in webview.

android mobile twitter page in webview not opening?

Also, if it's not redirecting you to the mobile version of twitter, you can just append mobile to it, i.e. mobile.twitter.com

Sign up to request clarification or add additional context in comments.

1 Comment

Well don't I feel sheepish. I searched through countless webview posts but for some reason didn't think to actually search for a solution involving Twitter. I guess I should have since it is popular enough and someone was bound to have had the same problem. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.