I want the android web view to display the desktop website rather than mobile website. Even after setting the user agent to desktop, still I see the mobile site being loaded.

String newUA = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";

WebSettings webSettings2 = webDisqus.getSettings();
        webSettings2.setJavaScriptEnabled(true);
        webSettings2.setBuiltInZoomControls(true);
        webDisqus.requestFocusFromTouch();
        webDisqus.setWebViewClient(new WebViewClient());
        webDisqus.setWebChromeClient(new WebChromeClient());
        webDisqus.getSettings().setUserAgentString(newUA);
        webDisqus.loadUrl("http://www.philly.com");

Please help to display to the desktop website rather than mobile website

有帮助吗?

解决方案

Web sites use a variety of mechanisms to decide to serve a mobile version of a page; the user agent is just one of them. They may set a cookie or some other piece of state that will always redirect to the mobile page after you've visited once. They might look at screen dimensions and do it that way. It's very hard to say what this particular website is doing. Maybe try clearing cookies?

Are you certain that the UA you have set is a desktop UA that the site recognises as a desktop browser?

其他提示

You can use setDesktopMode(true) from this WebView subclass or implement something similar to setDesktopMode() using the following WebView methods:

mWebView.getSettings().setUserAgentString(MODIFIED_OR_DESKTOP_USERAGENT);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true); 

This code (a) modifies the user-agent not to include the words "mobile" or "Android" and (b) adjusts the viewport to a larger width.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top