Hi,
I tried following with an Android App (API Level 29):
var _currentPermissionGranted = false;
Future<LocationPermission> _checkLocationPermission() {
checkPermission().then((permission) {
print(permission); // PROBLEM: always returns LocationPermission.deniedForever
if (permission == null)
return;
var newPermission = false;
if ([LocationPermission.always, LocationPermission.whileInUse].contains(permission))
newPermission = true;
if (permission == LocationPermission.denied)
requestPermission().then((status) {
_currentPosition = null; // _currentPosition will be set through PositionStreamSubscription later
setState(() {});
});
if (newPermission != _currentPermissionGranted) {
setState(() {
_currentPermissionGranted = newPermission;
});
}
});
}
@override
Widget build(BuildContext context) {
_checkLocationPermission();
if (_currentPermissionGranted) {doSth();}
return ...
}
When I start my app for the first time, I get the permission reguest. Then, I choose "Ask every time", then the checkPermssion() returns LocationPermission.whileInUse and the position data is streamed.
But on every further restart/widget initialisation, checkPermission() returns LocationPermission.deniedForever for any reasons. However, the System App Settings still shows "Ask every time". Is there a problem with how did I use the API?
I'm having similar issue on Android Emulator API 30.
@S-Man42 , @aramayyes , thank you for reporting this issue. I am looking into it.
@mvanbeusekom, are there any news?
I'm a novice, but wiping the emulator's data* might help.
_*Open the AVD manager and in the list of devices, all the way on the right hand side you click the dropdown arrow and select Wipe Data_

@mgav, thank you for reply, but it didn't help.
Any news? I don't want to change this package for this issue. 23 days and this issue still open. It smells like react-native package.
Hi @aramayyes, @Galti,
Have been thrown of on this issue since the OP mentioned this issue occurs on API 29 while this issue actually only happens on API 30 (selecting the "One time" permission is introduced in Android 11).
Long story short, I can reproduce the issue on API 30 and will be introducing a fix today (as part of release 6.1.0).
I've experienced this today on a fully updated Google Pixel XL2 and flutter-geolocator 6.1.13.
To reproduce: Run the example app (I've tried the default target API 28 and 30) on Android 11, API 30. Quit and close the example app. Long press the example app icon > App info > Permissions > Location and choose 'Ask every time'. Open the example app and choose 'getPermissionStatus'. 'LocationPermission.deniedForever' appears.
Still happening on API 30 Emulator
@dsgriffin which version of the Geolocator are you using? This problem has been solved in version 7.0.0 of the Geolocator, you can read detailed explanation on our wiki: https://github.com/Baseflow/flutter-geolocator/wiki/Breaking-changes-in-7.0.0.
@mvanbeusekom I'm using 7.0.1, and testing with the deny and ask every time permissions on Android Emulator SDK 30 & real devices.
var locationPermission = await Geolocator.checkPermission();
if (locationPermission == LocationPermission.denied) {
locationPermission = await Geolocator.requestPermission();
// Location permissions are permanently denied (cannot ask again) or Location Services are disabled
if (locationPermission == LocationPermission.deniedForever) {
return;
}
// Permission was denied - explain to user why we need it and ask again
if (locationPermission == LocationPermission.denied) {
await showRequestLocationDialog();
locationPermission = await Geolocator.requestPermission();
if (locationPermission != LocationPermission.whileInUse && locationPermission != LocationPermission.always) {
return;
}
}
}
The problem is that it never seems to return LocationPermission.denied on Android:
1) if the location permission is set to Deny on the app then it's deniedForever
2) if the location permission is set to Ask Every Time it returns deniedForever, which is a bigger issue
Is there any way to resolve this? Cheers
Most helpful comment
Hi @aramayyes, @Galti,
Have been thrown of on this issue since the OP mentioned this issue occurs on API 29 while this issue actually only happens on API 30 (selecting the "One time" permission is introduced in Android 11).
Long story short, I can reproduce the issue on API 30 and will be introducing a fix today (as part of release 6.1.0).