Skip to content

Commit

Permalink
NmeaClient: check ACCESS_FINE_LOCATION permission (#1540)
Browse files Browse the repository at this point in the history
`locationManager.addNmeaListener()` requires the ACCESS_FINE_LOCATION
permission. With only reduced locations enabled this would cause an
exception.
  • Loading branch information
SebastianKeller authored Jul 29, 2024
1 parent 4582308 commit f71c3a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.baseflow.geolocator.location;

import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.GnssStatus;
import android.location.Location;
import android.location.LocationManager;
Expand Down Expand Up @@ -73,9 +75,12 @@ public void start() {

if (locationOptions != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) {
locationManager.addNmeaListener(nmeaMessageListener, null);
locationManager.registerGnssStatusCallback(gnssCallback, null);
listenerAdded = true;
if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
locationManager.addNmeaListener(nmeaMessageListener, null);
locationManager.registerGnssStatusCallback(gnssCallback, null);
listenerAdded = true;
}
}
}
}
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.6.0
version: 4.6.1

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

0 comments on commit f71c3a0

Please sign in to comment.