Setting Webview to View Desktop Site and Not Mobile Site

Setting WebView to view Desktop Site and Not Mobile Site

Change the user agent of webview

 String newUA="Foo/"; // Change this to desired UA

like

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

How to open desktop site in webview in android

This is the perfect solution:

 private static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36";
private static final String MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; U; Android 4.4; en-us; Nexus 4 Build/JOP24G) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";

//Choose Mobile/Desktop client.
WebSettings settings = mWebView.getSettings();
settings.setUserAgentString(DESKTOP_USER_AGENT);


UPDATE

The above MOBILE_USER_AGENT is no longer supported.
so use the given below user agent

private static final String MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; Android 9; Redmi 6 Pro Build/PKQ1.180917.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.105 Mobile Safari/537.36";

Want to load desktop version in my webview using uastring

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";


Related Topics



Leave a reply



Submit