问题
I am developing an app for tablets like samsung galaxy, moto xoom and kindle fire.
My webview is not loading the desktop version of urls which I am giving.
I tried by setting the user Agent, but I dont know whats the exact \"ua string\" will solve my issue. When I took log of ua string I got the following
Code :
String ua = m_webview.getSettings().getUserAgentString() ;
Log.i(\"AboutActivity\", \"UA = \"+ua) ;
UA String:
UA = Mozilla/5.0 (Linux; U; Android 3.1; en-US; GT-P7500 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13
I read somewhere that I need to remove the \"mobile\" in the ua string but I didnt get \"mobile\" in the printed ua string.
I have tried the following ua string by adding desktop in it, even though its not coming
String ua = \"Mozilla/5.0 (Linux; U; Android 3.1; en-US; GT-P7500 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Desktop Safari/534.13\";
mWebview.getSettings().setUserAgentString(ua);
回答1:
It might be that they know you are on a mobile phone because you have Android
in the user agent. Try something more desktop browser looking such as:
String ua = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
回答2:
This is working for me: Refer this
public void setDesktopMode(final boolean enabled) {
final WebSettings webSettings = webview.getSettings();
final String newUserAgent;
if (enabled) {
newUserAgent = webSettings.getUserAgentString().replace("Mobile", "eliboM").replace("Android", "diordnA");
}
else {
newUserAgent = webSettings.getUserAgentString().replace("eliboM", "Mobile").replace("diordnA", "Android");
}
webSettings.setUserAgentString(newUserAgent);
webSettings.setUseWideViewPort(enabled);
webSettings.setLoadWithOverviewMode(enabled);
webSettings.setSupportZoom(enabled);
webSettings.setBuiltInZoomControls(enabled);
}
来源:https://stackoverflow.com/questions/8309796/want-to-load-desktop-version-in-my-webview-using-uastring