Skip to content

Commit 9b7a049

Browse files
authored
Start position stream after enabling location service (#1497)
* Start position stream after enabling location service * Start position stream after enabling location service
1 parent eaa173f commit 9b7a049

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

geolocator_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.5.5
2+
3+
* Fixes a bug where location stream is not automatically started when enabling the location services.
4+
15
## 4.5.4
26

37
* Fixes a bug where the `getPositionStream` was not informed of the location service resolution result. This resulted in a stream that was kept open indefinitely.

geolocator_android/android/src/main/java/com/baseflow/geolocator/GeolocatorPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public void onServiceDisconnected(ComponentName name) {
5656
@Nullable private ActivityPluginBinding pluginBinding;
5757

5858
public GeolocatorPlugin() {
59-
permissionManager = new PermissionManager();
60-
geolocationManager = new GeolocationManager();
61-
locationAccuracyManager = new LocationAccuracyManager();
59+
permissionManager = PermissionManager.getInstance();
60+
geolocationManager = GeolocationManager.getInstance();
61+
locationAccuracyManager = LocationAccuracyManager.getInstance();
6262
}
6363

6464
@Override

geolocator_android/android/src/main/java/com/baseflow/geolocator/location/GeolocationManager.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@
1818
public class GeolocationManager
1919
implements io.flutter.plugin.common.PluginRegistry.ActivityResultListener {
2020

21+
private static GeolocationManager geolocationManagerInstance = null;
22+
2123
private final List<LocationClient> locationClients;
2224

23-
public GeolocationManager() {
25+
private GeolocationManager() {
2426
this.locationClients = new CopyOnWriteArrayList<>();
2527
}
2628

29+
public static synchronized GeolocationManager getInstance() {
30+
if (geolocationManagerInstance == null) {
31+
geolocationManagerInstance = new GeolocationManager();
32+
}
33+
34+
return geolocationManagerInstance;
35+
}
36+
2737
public void getLastKnownPosition(
2838
Context context,
2939
boolean forceLocationManager,

geolocator_android/android/src/main/java/com/baseflow/geolocator/location/LocationAccuracyManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@
1111

1212
public class LocationAccuracyManager {
1313

14+
private LocationAccuracyManager() {}
15+
16+
private static LocationAccuracyManager locationAccuracyManagerInstance = null;
17+
18+
public static synchronized LocationAccuracyManager getInstance() {
19+
if (locationAccuracyManagerInstance == null) {
20+
locationAccuracyManagerInstance = new LocationAccuracyManager();
21+
}
22+
23+
return locationAccuracyManagerInstance;
24+
}
25+
1426
public LocationAccuracyStatus getLocationAccuracy(Context context, ErrorCallback errorCallback) {
1527
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
1628
== PackageManager.PERMISSION_GRANTED) {

geolocator_android/android/src/main/java/com/baseflow/geolocator/permission/PermissionManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,31 @@
1616
import com.baseflow.geolocator.errors.ErrorCodes;
1717
import com.baseflow.geolocator.errors.PermissionUndefinedException;
1818

19+
import java.security.Permission;
1920
import java.util.*;
2021

2122
@SuppressWarnings("deprecation")
2223
public class PermissionManager
2324
implements io.flutter.plugin.common.PluginRegistry.RequestPermissionsResultListener {
2425

26+
private PermissionManager() {}
27+
2528
private static final int PERMISSION_REQUEST_CODE = 109;
2629

30+
private static PermissionManager permissionManagerInstance = null;
31+
2732
@Nullable private Activity activity;
2833
@Nullable private ErrorCallback errorCallback;
2934
@Nullable private PermissionResultCallback resultCallback;
3035

36+
public static synchronized PermissionManager getInstance() {
37+
if (permissionManagerInstance == null) {
38+
permissionManagerInstance = new PermissionManager();
39+
}
40+
41+
return permissionManagerInstance;
42+
}
43+
3144
public LocationPermission checkPermissionStatus(Context context)
3245
throws PermissionUndefinedException {
3346
List<String> permissions = getLocationPermissionsFromManifest(context);

geolocator_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: geolocator_android
22
description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator.
33
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android
44
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
5-
version: 4.5.4
5+
version: 4.5.5
66

77
environment:
88
sdk: ">=2.15.0 <4.0.0"

0 commit comments

Comments
 (0)