I need to open desktop site in android webview for that i have tried as below but it is not working.
String newUA= \"Mozilla/5.0 (X11; U; Linux i686; en-US;
You can use setDesktopMode(true) from this WebView subclass or read how it's implemented. What is does is (a) set the user-agent not to include the words "mobile" or "Android" and (b) set the viewport to a larger width.
For Mobile User-Agent
webview.getSettings().setUserAgentString("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");
For Desktop site Agent
browser.getSettings().setUserAgentString("Mozilla/5.0 (Linux; diordnA 7.1.1; suxeN 6 Build/N6F26U; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 eliboM Safari/537.36");
A lot of searches this code fine working on Android webview
.
Try this:
webView = (WebView)findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(false);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
This is working for me: refer to this as mentioned by @saurabh gutpa as well
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);
}
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);