diff --git a/src/Essentials/src/Geolocation/Geolocation.android.cs b/src/Essentials/src/Geolocation/Geolocation.android.cs index 6aac99ad2b1e..a32fd1191299 100644 --- a/src/Essentials/src/Geolocation/Geolocation.android.cs +++ b/src/Essentials/src/Geolocation/Geolocation.android.cs @@ -178,7 +178,7 @@ public async Task StartListeningForegroundAsync(GeolocationListeningReques if (listeningProviders.Count == 0) listeningProviders.Add(providerInfo.Provider); - var continuousListener = new ContinuousLocationListener(LocationManager, providerInfo.Accuracy, listeningProviders); + continuousListener = new ContinuousLocationListener(LocationManager, providerInfo.Accuracy, listeningProviders); continuousListener.LocationHandler = HandleLocation; continuousListener.ErrorHandler = HandleError; diff --git a/src/Essentials/test/DeviceTests/Tests/Geolocation_Tests.cs b/src/Essentials/test/DeviceTests/Tests/Geolocation_Tests.cs index 66812c7b1796..f95e4560038a 100644 --- a/src/Essentials/test/DeviceTests/Tests/Geolocation_Tests.cs +++ b/src/Essentials/test/DeviceTests/Tests/Geolocation_Tests.cs @@ -88,5 +88,25 @@ await MainThread.InvokeOnMainThreadAsync(async () => Assert.True(location.Timestamp < DateTimeOffset.UtcNow); Assert.True(location.Timestamp > DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(1))); } + + [Fact] + [Trait(Traits.InteractionType, Traits.InteractionTypes.Human)] + public async Task Geolocation_IsListeningForeground() + { + await MainThread.InvokeOnMainThreadAsync(async () => + { + await Permissions.RequestAsync(); + }); + + var request = new GeolocationListeningRequest(GeolocationAccuracy.Best); + request.DesiredAccuracy = GeolocationAccuracy.Low; + request.MinimumTime = TimeSpan.FromSeconds(5); + + bool hasServiceStarted = await Geolocation.StartListeningForegroundAsync(request); + + bool isListeningForeground = Geolocation.IsListeningForeground; + + Assert.Equal(hasServiceStarted, isListeningForeground); + } } }