A Microsoft framework for building cross-platform mobile apps using .NET and C# with native performance and user interfaces.
GeoWebViewRenderer.cs
using System;
using Android.App;
using Android.Content;
using Android.Provider;
using Android.Webkit;
using AndroidX.Core.Content;
using Java.IO;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(GeoLocTest.GeoWebView), typeof(GeoLocTest.Droid.GeoWebViewRenderer))]
namespace GeoLocTest.Droid
{
public class GeoWebViewRenderer : WebViewRenderer
{
public GeoWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
Control.Settings.JavaScriptEnabled = true;
Control.Settings.AllowFileAccess = true;
Control.Settings.AllowFileAccessFromFileURLs = true;
Control.Settings.AllowContentAccess = true;
Control.Settings.BlockNetworkImage = false;
Control.Settings.AllowUniversalAccessFromFileURLs = true;
Control.Settings.DomStorageEnabled = true;
Control.Settings.SetAppCacheEnabled(false);
Control.Settings.DatabaseEnabled = true;
Control.Settings.DomStorageEnabled = true;
MyWebClient cwc = new MyWebClient(MainActivity.Instance);
Control.SetWebChromeClient(cwc);
Control.Settings.SetGeolocationEnabled(true);
Control.Settings.SetGeolocationDatabasePath(Control.Context.FilesDir.Path);
Control.LoadUrl("https://www.google.com/");
}
}
public class MyWebClient : WebChromeClient
{
Activity mActivity = null;
public MyWebClient(Activity activity)
{
mActivity = activity;
}
public override void OnGeolocationPermissionsShowPrompt(string origin, GeolocationPermissions.ICallback callback)
{
callback.Invoke(origin, true, true);
}
}
}