i am using xamarin android but if you provide java code is also good. I noticed when i open certain url pages, i get a blank page but if i open thesame webpage in google chrome on my test device it opens nicey.
I have done the following with no luck:
WebView web_view = view.FindViewById<WebView>(Resource.Id.webView1);
web_view.SetWebChromeClient(new WebChromeClient());
web_view.Settings.LoadWithOverviewMode = true;
web_view.Settings.JavaScriptEnabled = true;
web_view.Settings.CacheMode = CacheModes.Normal;
web_view.Settings.UserAgentString = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
web_view.Settings.DomStorageEnabled = true;
web_view.Settings.DatabaseEnabled = true;
web_view.Settings.UseWideViewPort = true;
web_view.Settings.SetPluginState(WebSettings.PluginState.On);
web_view.LoadUrl("url_here");
I have also added "android:usesCleartextTraffic="true"" in my android application tag manifest.
Offcourse i also added the internet permission and i using https but i get a blank page.
CodePudding user response:
I have fixed this issue... First create a webviewclient class :
public class MyBabyclient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
{
view.LoadUrl(request.Url.ToString());
return false;
}
}
Then assign it to your webview : web_view.SetWebViewClient(new MyBabyclient());
More info can be seen here : https://docs.microsoft.com/en-us/xamarin/android/user-interface/controls/web-view