From 9da73bf9c90348e536bfe40d2516710c16247b4f Mon Sep 17 00:00:00 2001 From: dartasen Date: Thu, 18 Apr 2024 17:02:24 +0200 Subject: [PATCH 1/2] Fix for continuous listener always null --- src/Essentials/src/Geolocation/Geolocation.android.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 53af086f0a1aef8cd7763c21fb9bdf20996a6b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Su=C3=A1rez?= Date: Fri, 10 May 2024 10:44:32 +0200 Subject: [PATCH 2/2] Added test --- .../DeviceTests/Tests/Geolocation_Tests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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); + } } }