Skip to content

Commit f71c3a0

Browse files
NmeaClient: check ACCESS_FINE_LOCATION permission (#1540)
`locationManager.addNmeaListener()` requires the ACCESS_FINE_LOCATION permission. With only reduced locations enabled this would cause an exception.
1 parent 4582308 commit f71c3a0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.baseflow.geolocator.location;
22

3+
import android.Manifest;
34
import android.annotation.SuppressLint;
45
import android.annotation.TargetApi;
56
import android.content.Context;
7+
import android.content.pm.PackageManager;
68
import android.location.GnssStatus;
79
import android.location.Location;
810
import android.location.LocationManager;
@@ -73,9 +75,12 @@ public void start() {
7375

7476
if (locationOptions != null) {
7577
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) {
76-
locationManager.addNmeaListener(nmeaMessageListener, null);
77-
locationManager.registerGnssStatusCallback(gnssCallback, null);
78-
listenerAdded = true;
78+
if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
79+
== PackageManager.PERMISSION_GRANTED) {
80+
locationManager.addNmeaListener(nmeaMessageListener, null);
81+
locationManager.registerGnssStatusCallback(gnssCallback, null);
82+
listenerAdded = true;
83+
}
7984
}
8085
}
8186
}

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.6.0
5+
version: 4.6.1
66

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

0 commit comments

Comments
 (0)