Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

android - Problems loading mobile.twitter in webview

When I try to load the following urls in a Webview all i get is black twitter background with loading spinner. The page is loaded, as WebViewClient.onPageFinished is called. However the page loads ok in the standard Android browser.

https://twitter.com/#!/scottyab or https://mobile.twitter.com/#!/scottyab

I'm thinking Twitter changed their mobile website as this worked a month or so ago. Anyone else experiencing this?

Updated: javascript enabled mWebView.getSettings().setJavaScriptEnabled(true);

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Those are indeed dirty hacks. Changing the User Agent is really a nasty solution and should never be done. When loading twitter.com in a webview, you'd better try the piece of code given there : https://stackoverflow.com/a/6625418/162178

For lazy clickers I'll give it here :

webView.getSettings().setDomStorageEnabled(true);

All credits goes to gregm, who gave this one :)

Happy coding !

Edit: Just a little update to justify this choice, User Agent are meant to give the visited site the info about who's the client. If one day Twitter makes special changes dedicated to Android, they will definitely use the User Agent to achieve that. If you tell them your an iPhone or whatever you might never get redirected or more simply never get the css intended specially for Android.

And in a more political matter, if everyone changes it's User Agent, site statistics will be wrong and they might never see there are a lot of Androids coming to their website. ^^ (To maybe consider engaging the proper updates to their website). And this whole thing is not only for Twitter web clients. So be nice.

Benjamin's answers here seems quite good to (using Java's Reflection to make it backwards compatible if I'm correct)

So again don't change the User Agent it is very bad for your app and the web health. And should simply be banned from any code out there. Thanks :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...