I've done quite a lot of research on Stack Overflow and a lot of Google research but nothing I find is actually working out for me. I want the site to view the desktop site instead of the mobile site. How do I do this? I want it to directly go to the Desktop site.
WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.loadUrl("http://www.apotter96.webs.com/"); }
Part 2: How to force desktop version of popular online site on Android. If you have the app on your Android phone, you have to disable the app before switch to desktop version in browser. The operation is simple: go to "Settings" > "Apps", find the target app and press the "Disable" button to turn it off.
Google combined WebView with Google Chrome for versions 7.0, 8.0 and 9.0. However, with Android 10.0, it went back to having it as a separate component. Users can update WebView in Android 10 through Google Play Store.
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);
This method helps you to set DesktopMode on webview
public void setDesktopMode(WebView webView,boolean enabled) { String newUserAgent = webView.getSettings().getUserAgentString(); if (enabled) { try { String ua = webView.getSettings().getUserAgentString(); String androidOSString = webView.getSettings().getUserAgentString().substring(ua.indexOf("("), ua.indexOf(")") + 1); newUserAgent = webView.getSettings().getUserAgentString().replace(androidOSString, "(X11; Linux x86_64)"); } catch (Exception e) { e.printStackTrace(); } } else { newUserAgent = null; } webView.getSettings().setUserAgentString(newUserAgent); webView.getSettings().setUseWideViewPort(enabled); webView.getSettings().setLoadWithOverviewMode(enabled); webView.reload(); }
Call it like that
Mobile mode : setDesktopMode(webView, false);
Desktop mode : setDesktopMode(webView, true);
For Kotlin:
fun setDesktopMode(webView: WebView, enabled: Boolean) { var newUserAgent: String? = webView.settings.userAgentString if (enabled) { try { val ua: String = webView.settings.userAgentString val androidOSString: String = webView.settings.userAgentString.substring( ua.indexOf("("), ua.indexOf(")") + 1 ) newUserAgent = webView.settings.userAgentString.replace(androidOSString, "(X11; Linux x86_64)") } catch (e: Exception) { e.printStackTrace() } } else { newUserAgent = null } webView.settings.apply { userAgentString = newUserAgent useWideViewPort = enabled loadWithOverviewMode = enabled } webView.reload() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With