Problem with Geolocation in WebView - Xamarin

Viewed 39

I have created an application with a web view. The open page contains the GPS positioning, but it doesn't work in the app even after enabling it. The app crashes during compilation and throws errors:

  • Severity Code Description Project File Line Suppression State Error XARDF7023: System.IO.DirectoryNotFoundException: Could not find a part of the path 'AccessibilityManagerCompat_TouchExplorationStateChangeListenerImplementor.class'. at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data) at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost) at Xamarin.Android.Tasks.RemoveDirFixed.RunTask()

  • Severity Code Description Project File Line Suppression State Error XARDF7024: System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.

    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound, WIN32_FIND_DATA& data) at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost) at Xamarin.Android.Tasks.RemoveDirFixed.RunTask() 0

Main page:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:Taxi_Slovensko"
         x:Class="Taxi_Slovensko.MainPage">

<!--<WebView x:Name="Broswer" HeightRequest="1920" WidthRequest="1080"/>-->
<local:CustomWebViewControl x:Name="Broswer"/>

Created custom control for WebView in PCL project:

    public class CustomWebViewControl : WebView
{
}

And created CustomWebViewRenderer in android project:

 [assembly: ExportRenderer(typeof(CustomWebViewControl), typeof(CustomWebViewRenderer))]

namespace Taxi_Slovensko.Droid
{
    [Obsolete]
    public class CustomWebViewRenderer : WebViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
        {
            base.OnElementChanged(e);
            Control.Settings.JavaScriptEnabled = true;
            Control.SetWebChromeClient(new MyWebClient());
        }
    }

    public class MyWebClient : WebChromeClient
    {
        public override void OnGeolocationPermissionsShowPrompt(string origin, GeolocationPermissions.ICallback callback)
        {
            callback.Invoke(origin, true, false);
        }
    }
}

I will be very grateful for any help

1 Answers

I have done a sample with your code, and the webview worked correctly. When the website requested the location permission, the OnGeolocationPermissionsShowPrompt method will be invoked.

So you can create a new project to check if the error will appear or not. In addition, according to the error message, the problem is an IO exception, it shouldn't be about the webview.

Finally, you can also try to debug to find which line causes this error.

Related