PositionError event is not raised when GPS is disabled in device settings (Android)
mindphaser opened this issue · comments
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
- Use
await CrossGeolocator.Current.StartListeningAsync()
, subscribe to events PositionChanged and PositionError. - 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();