android – Upload the web version of a website and not the mobile version in a WebView

Question:

How to load a complete website in Xamarin.Android WebView ? He is bringing the mobile version.

Example:

I'm talking to WebView go to

https://www.mysite.com.br

And it's bringing:

https://m.mysite.com.br

Answer:

To solve this problem you must change the User-Agent(UA) of the WebView. Reading Xamarin's WebView documentation , by default, if nothing is told it will build based on the device version. As it will create a UA based on a mobile version, the site recognizes and redirects to the mobile version. If you overwrite UA and say you are "using" a computer, the site will not redirect.

A code example to change the UA:

public class SurveyWebViewClient : WebViewClient
        {
            public override bool ShouldOverrideUrlLoading(WebView view, string url)
            {
                view.Settings.UserAgentString = "ua-string";
                view.LoadUrl(url);


                return true;
            }
        }

Where's the UA-String you can use this from Google Chrome on Windows 7:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36

If you want another UA, you can consult this list .

Scroll to Top