From ee20a4f844635c4ecb547631fb014d5525f33aea Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Fri, 8 Aug 2025 17:24:25 +0500 Subject: [PATCH] Add fix for multiple dialog showing issue in FusedLocationClient.java and added min interval to show --- .../geolocator/location/FusedLocationClient.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java index bef3090c..faab095b 100644 --- a/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java +++ b/geolocator_android/android/src/main/java/com/baseflow/geolocator/location/FusedLocationClient.java @@ -34,6 +34,9 @@ class FusedLocationClient implements LocationClient { private static final String TAG = "FlutterGeolocator"; + private static final long DIALOG_SHOW_INTERVAL_MS = 30 * 60 * 1000; // 30 minutes + private static boolean isDialogShowing = false; + private static long lastDialogShowTime = 0; private final Context context; private final LocationCallback locationCallback; @@ -200,6 +203,8 @@ public void getLastKnownPosition( } public boolean onActivityResult(int requestCode, int resultCode) { + isDialogShowing = false; + if (requestCode == activityRequestCode) { if (resultCode == Activity.RESULT_OK) { if (this.locationOptions == null @@ -252,10 +257,19 @@ public void startPositionUpdates( int statusCode = rae.getStatusCode(); if (statusCode == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) { try { + long currentTime = System.currentTimeMillis(); + if (isDialogShowing || (lastDialogShowTime != 0 && (currentTime - lastDialogShowTime) < DIALOG_SHOW_INTERVAL_MS)) { + return; + } + // Show the dialog by calling startResolutionForResult(), and check the // result in onActivityResult(). rae.startResolutionForResult(activity, activityRequestCode); + + isDialogShowing = true; + lastDialogShowTime = currentTime; } catch (IntentSender.SendIntentException sie) { + isDialogShowing = false; errorCallback.onError(ErrorCodes.locationServicesDisabled); } } else {