Want to load desktop version in my webview using uastring

倾然丶 夕夏残阳落幕 提交于 2019-11-26 11:37:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!