Skip to content

Commit eaa173f

Browse files
authored
Make sure the GeolocationManager instance is shared (#1466)
1 parent 9f4bc49 commit eaa173f

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-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.4
2+
3+
* 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.
4+
15
## 4.5.3+1
26

37
* Reverts `androidx.core:core` to version `1.9.0`.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class GeolocatorLocationService extends Service {
5050
public void onCreate() {
5151
super.onCreate();
5252
Log.d(TAG, "Creating service.");
53-
geolocationManager = new GeolocationManager();
5453
}
5554

5655
@Override
@@ -177,6 +176,10 @@ public void setActivity(@Nullable Activity activity) {
177176
this.activity = activity;
178177
}
179178

179+
public void setGeolocationManager(@Nullable GeolocationManager geolocationManager) {
180+
this.geolocationManager = geolocationManager;
181+
}
182+
180183
private void releaseWakeLocks() {
181184
if (wakeLock != null && wakeLock.isHeld()) {
182185
wakeLock.release();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
6868
this.permissionManager, this.geolocationManager, this.locationAccuracyManager);
6969
methodCallHandler.startListening(
7070
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());
71-
streamHandler = new StreamHandlerImpl(this.permissionManager);
71+
streamHandler = new StreamHandlerImpl(this.permissionManager, this.geolocationManager);
7272
streamHandler.startListening(
7373
flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger());
7474

@@ -161,6 +161,7 @@ private void unbindForegroundService(Context context) {
161161
private void initialize(GeolocatorLocationService service) {
162162
Log.d(TAG, "Initializing Geolocator services");
163163
foregroundLocationService = service;
164+
foregroundLocationService.setGeolocationManager(geolocationManager);
164165
foregroundLocationService.flutterEngineConnected();
165166

166167
if (streamHandler != null) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class StreamHandlerImpl implements EventChannel.StreamHandler {
3333
@Nullable private GeolocationManager geolocationManager;
3434
@Nullable private LocationClient locationClient;
3535

36-
public StreamHandlerImpl(PermissionManager permissionManager) {
36+
public StreamHandlerImpl(PermissionManager permissionManager, GeolocationManager geolocationManager) {
3737
this.permissionManager = permissionManager;
38-
geolocationManager = new GeolocationManager();
38+
this.geolocationManager = geolocationManager;
3939
}
4040

4141
public void setForegroundLocationService(

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.3+1
5+
version: 4.5.4
66

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

0 commit comments

Comments
 (0)