Desktop Mode Code
//put onCreate
} public void setDesktopMode(WebView webview1,boolean enabled) { String newUserAgent = webview1.getSettings().getUserAgentString(); if (enabled) { try { String ua = webview1.getSettings().getUserAgentString(); String androidOSString = webview1.getSettings().getUserAgentString().substring(ua.indexOf("("), ua.indexOf(")") + 1); newUserAgent = webview1.getSettings().getUserAgentString().replace(androidOSString, "(X11; Linux x86_64)"); } catch (Exception e) { e.printStackTrace(); } } else { newUserAgent = null; } webview1.getSettings().setUserAgentString(newUserAgent); webview1.getSettings().setUseWideViewPort(enabled); webview1.getSettings().setLoadWithOverviewMode(enabled); webview1.reload();
//set Button onClick Desktop
setDesktopMode(webview1, true);
//set Button onClick Mobile
setDesktopMode(webview1, false);
} public void setDesktopMode(WebView webview1,boolean enabled) { String newUserAgent = webview1.getSettings().getUserAgentString(); if (enabled) { try { String ua = webview1.getSettings().getUserAgentString(); String androidOSString = webview1.getSettings().getUserAgentString().substring(ua.indexOf("("), ua.indexOf(")") + 1); newUserAgent = webview1.getSettings().getUserAgentString().replace(androidOSString, "(X11; Linux x86_64)"); } catch (Exception e) { e.printStackTrace(); } } else { newUserAgent = null; } webview1.getSettings().setUserAgentString(newUserAgent); webview1.getSettings().setUseWideViewPort(enabled); webview1.getSettings().setLoadWithOverviewMode(enabled); webview1.reload();
//set Button onClick Desktop
setDesktopMode(webview1, true);
//set Button onClick Mobile
setDesktopMode(webview1, false);
nice
ReplyDeleteI tried the same in spinner menu no error but no desktop version become ture it remains bydefault false
ReplyDeleteMy webview reloads but no dekstop view
Same here, no desktop view
ReplyDelete