jamesmontemagno / GeolocatorPlugin

Geolocation plugin for Xamarin and Windows
MIT License
294 stars 158 forks source link

PositionError event is not raised when GPS is disabled in device settings (Android) #320

Open mindphaser opened 4 years ago

mindphaser commented 4 years ago

Bug Information

Version Number of Plugin: 4.6.2.1 Device Tested On: Android emulator, base device: Pixel XL, Android 9.0, API 28 Simulator Tested On: Android emulator, base device: Pixel XL, Android 9.0, API 28 Version of VS: 16.4.3 Version of Xamarin: 16.4.000.308 (d16-4@4755fb3) Versions of other things you are using:

Steps to reproduce the Behavior

  1. Use await CrossGeolocator.Current.StartListeningAsync(), subscribe to events PositionChanged and PositionError.
  2. When app is running, go to device location settings and disable location.

    Expected Behavior

    When location is disabled, event PositionError should be raised.

    Actual Behavior

    PositionError is not raised because passive provider is added to GeolocationContinuousListener

    Code snippet

    Fix: In file GeolocatorImplementation.android.cs line 325 (just before listener = new GeolocationContinuousListener(Manager, minimumTime, providers);):

var providers = Providers; replace with: var providers = Providers.Where(p => !IgnoredProviders.Contains(p)).ToArray();