When I click on 'Keep While app in use' in location permission, I am again prompted to choose between 'All the Time' and 'Keep While app in use'. App stops asking permission when I either click 'All the time' or 'Don't ask again'.
I'm seeing this too, the plugin is unusable on android as it is
I believe the problem is caused by a call to Java that loses a parameter, but that happens over at the location_permissions package.
From what I understand, geolocator uses location_permissions, passing the permission level that's received in getCurrentPosition:
https://github.com/Baseflow/flutter-geolocator/blob/ad7ad26c4fb848f68a71d0b9946ccea43682f1b4/lib/geolocator.dart#L198-L211
In turn, location_permissions makes a call to native code, passing the permission level as an integer: (these code snippets won't render because it's code the location_permissions repository)
https://github.com/Baseflow/flutter-permission-plugins/blob/b3448a2ee46334fd113161ed67d55b68bb2384f1/packages/location_permissions/lib/src/location_permissions.dart#L31-L41
However, the native code seems to ignore this parameter:
https://github.com/Baseflow/flutter-permission-plugins/blob/b3448a2ee46334fd113161ed67d55b68bb2384f1/packages/location_permissions/android/src/main/java/com/baseflow/location_permissions/LocationPermissionsPlugin.java#L125-L130
In fact, there seems to already be an issue open for this: https://github.com/Baseflow/flutter-permission-plugins/issues/41
In any case, if you're having this issue, I worked around it by directly calling the geolocator's native method. I needed to call getCurrentPosition(), so here's how I did it:
var channel = MethodChannel('flutter.baseflow.com/geolocator/methods');
Map<String, dynamic> params = <String, dynamic>{
'accuracy': LocationAccuracy.high.value,
'distanceFilter': 0,
'forceAndroidLocationManager': false, // <- choose what's best for you
'timeInterval': 0,
};
Map<dynamic, dynamic> positionMap = await channel.invokeMethod(
'getCurrentPosition',
params,
);
// Get the properties you need here. You may want to check if they exist first.
double latitude = positionMap['latitude'];
double longitude = positionMap['longitude'];
Note that in this case you'll have to manage permissions yourself.
We have just released a hotfix for the issue mentioned by @rafaeltakahashi. This means it should automatically also fix the issue in the Geolocator plugin (since it references the Location Permission using the ^3.0.0 version indicator).
Would appreciate any feedback on this ;)
@mvanbeusekom After a pub upgrade, I can confirm it's working. Thanks!
@mvanbeusekom Which version do I need? I am using version ^5.3.2+2 and still have the problem.
@mvanbeusekom Which version do I need? I am using version ^5.3.2+2 and still have the problem.
Hi @ndhbr, you should make sure of a few things:
final currentPosition = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.high,
locationPermissionLevel: GeolocationPermission.locationWhenInUse,
);
@rafaeltakahashi
Thanks for your answer.
I have both the location_permissions plugin version 3.0.0+1 and the parameters for the method call. Unfortunately, every time I call the location, the permission popup appears anyway to check if it is still "While in use".
@mvanbeusekom Which version do I need? I am using version ^5.3.2+2 and still have the problem.
Hi @ndhbr, you should make sure of a few things:
- That you have location_permissions version 3.0.0+1 in your pubspec.lock (run a pub upgrade if necessary)
- And that you're calling Geolocator's methods passing the permission level you need:
final currentPosition = await Geolocator().getCurrentPosition( desiredAccuracy: LocationAccuracy.high, locationPermissionLevel: GeolocationPermission.locationWhenInUse, );
it's working
thankyou so much
Most helpful comment
Hi @ndhbr, you should make sure of a few things: