Geolocator.checkPermission() is not giving LocationPermission.deniedForever status in Android of any version
🐛 Bug Report
Expected behavior
When user checks on Don't ask again in android version below 30 or User selects deny two times we should get deniedForever as Location permission .
Version: 7.4.0
Platform: Android
I am not able to reproduce the issue. Can you provide me some steps to reproduce your issue? Also, add information about which device/emulator (+ Android API level) you're using and your flutter doctor -v. The template below is an example of how can you can describe the issue you're mentioning.
What I did:
- Created a sample app using
flutter create issue_809 - Added
geolocator7.0.4. to mypubspec.yaml - Added a button which executes the
requestPermissionmethod. - Ran the app on an Android Emulator using API level 29 and logged the
resultof therequestPermissionmethod.
When denying the Location Permission once, LocationPermission.denied is logged in my console. When denying the Location Permission for the second time LocationPermission.deniedForever is logged like expected.
@florissmit1 thank you for your response. Please check out my detailed explanation .
What I did:
- Created new application using
flutter create location_permission. - Added
geolocator: ^7.4.0inpubspec.yaml. - Added location permission in
AndroidManifest.xml(please mention this step in your pub documentation). - replaced
_incrementCounterfunction from flutter boilerplate counter app code with below code. - Launched the application in Android 9 real device and Pixel 4 API 30 simulator.
Testing:
i) For the first time if the when user tap on floating + button which call _incrementCounter() the native permission is shown and user denied then the finalPermission is LocationPermission.denied which is fine.
ii) For the second time when user tapped on the button native popup is shown with Don't ask again check box. When user checked the box and tapped on DENY then we see finalPermission as LocationPermission.denied but we expect LocationPermission.deniedForever.
Can you check if any issue with await Geolocator.checkPermission();
Future<void> _incrementCounter() async{
LocationPermission permission = await Geolocator.checkPermission();
if(permission == LocationPermission.denied){
await Geolocator.requestPermission();
}
LocationPermission finalPermission = await Geolocator.checkPermission();
print(finalPermission.toString());
}
Hi @vmadupu9,
That is correct, the Android API for checking permission only returns if permissions are "denied" or "granted". The API does not support returning the "denied forever" status unfortunately. There used to be a workaround but since Android API 30 this resulted into more issues then it solved and we removed it from the plugin. More details can be found in our wiki article here.