flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

Geolocator.checkPermission() is not giving LocationPermission.deniedForever status in Android of any version

Open vmadupu9 opened this issue 5 years ago • 3 comments

🐛 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

vmadupu9 avatar Aug 11 '21 06:08 vmadupu9

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 geolocator 7.0.4. to my pubspec.yaml
  • Added a button which executes the requestPermission method.
  • Ran the app on an Android Emulator using API level 29 and logged the result of the requestPermission method.

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 avatar Aug 11 '21 11:08 florissmit1

@florissmit1 thank you for your response. Please check out my detailed explanation .

What I did:

  1. Created new application using flutter create location_permission.
  2. Added geolocator: ^7.4.0 in pubspec.yaml.
  3. Added location permission in AndroidManifest.xml (please mention this step in your pub documentation).
  4. replaced _incrementCounter function from flutter boilerplate counter app code with below code.
  5. 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());
 } 

vmadupu9 avatar Aug 11 '21 12:08 vmadupu9

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.

mvanbeusekom avatar Aug 12 '21 05:08 mvanbeusekom