How to load WebView
from Xamarin.Android a complete site? He is bringing the mobile version.
Example:
I'm talking to WebView
go to
And it's bringing:
To resolve this problem you must change the WebView User-Agent (UA). Reading the documentation of Xamarin's WebView, by default, if nothing is told it will based on the version of the device. Because you will create a UA based on a mobile version, the site recognizes and redirects to the mobile version. If you override the UA and say that you are "using" a computer, the site will not redirect.
An example code 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 is UA-String you can use that of Google Chrome in 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 would like another UA, you can check this list .
[assembly:ExportRenderer(typeof(WebView), typeof(DesktopWebViewRenderer))]
public class DesktopWebViewRenderer : WebViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
Control.Settings.UserAgentString = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
}
}