Skip to content

Commit

Permalink
Start position stream after enabling location service (#1497)
Browse files Browse the repository at this point in the history
* Start position stream after enabling location service

* Start position stream after enabling location service
  • Loading branch information
mvanbeusekom authored May 2, 2024
1 parent eaa173f commit 9b7a049
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
4 changes: 4 additions & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.5.5

* Fixes a bug where location stream is not automatically started when enabling the location services.

## 4.5.4

* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public void onServiceDisconnected(ComponentName name) {
@Nullable private ActivityPluginBinding pluginBinding;

public GeolocatorPlugin() {
permissionManager = new PermissionManager();
geolocationManager = new GeolocationManager();
locationAccuracyManager = new LocationAccuracyManager();
permissionManager = PermissionManager.getInstance();
geolocationManager = GeolocationManager.getInstance();
locationAccuracyManager = LocationAccuracyManager.getInstance();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@
public class GeolocationManager
implements io.flutter.plugin.common.PluginRegistry.ActivityResultListener {

private static GeolocationManager geolocationManagerInstance = null;

private final List<LocationClient> locationClients;

public GeolocationManager() {
private GeolocationManager() {
this.locationClients = new CopyOnWriteArrayList<>();
}

public static synchronized GeolocationManager getInstance() {
if (geolocationManagerInstance == null) {
geolocationManagerInstance = new GeolocationManager();
}

return geolocationManagerInstance;
}

public void getLastKnownPosition(
Context context,
boolean forceLocationManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@

public class LocationAccuracyManager {

private LocationAccuracyManager() {}

private static LocationAccuracyManager locationAccuracyManagerInstance = null;

public static synchronized LocationAccuracyManager getInstance() {
if (locationAccuracyManagerInstance == null) {
locationAccuracyManagerInstance = new LocationAccuracyManager();
}

return locationAccuracyManagerInstance;
}

public LocationAccuracyStatus getLocationAccuracy(Context context, ErrorCallback errorCallback) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@
import com.baseflow.geolocator.errors.ErrorCodes;
import com.baseflow.geolocator.errors.PermissionUndefinedException;

import java.security.Permission;
import java.util.*;

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

private PermissionManager() {}

private static final int PERMISSION_REQUEST_CODE = 109;

private static PermissionManager permissionManagerInstance = null;

@Nullable private Activity activity;
@Nullable private ErrorCallback errorCallback;
@Nullable private PermissionResultCallback resultCallback;

public static synchronized PermissionManager getInstance() {
if (permissionManagerInstance == null) {
permissionManagerInstance = new PermissionManager();
}

return permissionManagerInstance;
}

public LocationPermission checkPermissionStatus(Context context)
throws PermissionUndefinedException {
List<String> permissions = getLocationPermissionsFromManifest(context);
Expand Down
2 changes: 1 addition & 1 deletion geolocator_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: geolocator_android
description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
version: 4.5.4
version: 4.5.5

environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down

0 comments on commit 9b7a049

Please sign in to comment.