Flutter - Android doesn't ask for permissions

16,218

Solution 1

After asking on the git of location plugin, I did this :

flutter clean

And I got the pop up asking for permissions.

Thank to this guy.

Solution 2

You can handle this kind of permission behavior in your code. Even if you never had installed your app on emulator this behavior can happen and you must handle this in your code because this can happen when your app are in final user hands.

This exception means that you're getting PermissionStatus.denied from checkPermissionStatus permission handler plugin method and this can happen when user hits Never ask again checkbox in android permission dialog and deny the request.

What is the most simple way to handle this?

If you get PermissionStatus.denied from checkPermissionStatus method you can show a dialog telling to the user that your app needs of that permission to provide a better experience and in this dialog you can redirect the user to Android permission settings where the user can enable the requested permission manually. You can do this using openAppSettings() method from permission handler plugin.

Maybe you should read this article, it's a little bit old but it shows the correct flow about how to ask and handle user permissions in android. This article doesn't talks about the new permissions changes in newer Android Q.

Solution 3

The error message tries to make it clear: Your device (you or someone else on the device you are testing on) has selected Never when Android asked for the permission previously.
This means that Android will not ask for the permission again.

Just try it on a different device or uninstall the app again.

Share:
16,218
Robouste
Author by

Robouste

Updated on June 08, 2022

Comments

  • Robouste
    Robouste almost 2 years

    I'm trying to get the current location of the device using the plugin location but Android never asks for permissions. I get this error:

    Exception has occurred. PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever- please open app settings, null))

    I have added the line below in every `AndroidManifest.xml´ file that I could find in the Android folder (no idea which one I should use actually, I found 3 of them)

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    

    I tried the plugin permission_handler to request them manually but still, no pop-up.

    I'm completely lost and I find nothing similar on the net. Here is the code :

    Future<LocationData> _getLocation() async {
      LocationData currentLocation;
      
      // returns a map with unreadable numbers which make no sense
      var t = await PermissionHandler()
          .requestPermissions([PermissionGroup.location]);
      
      // returns false
      var test = await location.requestPermission();
    
      try {
        currentLocation = await location.getLocation();
      } catch (e) {
        currentLocation = null;
      }
      return currentLocation;
    }
    

    Edit: I tried this on my device (OnePlus 6) and on an emulator (Pixel XL API 28). I've also tried to uninstall/reinstall the app.

  • Robouste
    Robouste about 5 years
    I also tried on the emulator, same result. I've uninstalled/reinstalled the app, same result.
  • Gbenga B Ayannuga
    Gbenga B Ayannuga over 2 years
    @Robouste i am also facing this issue now.. i don't no. i have try flutter clean, uninstall, reinstall. it keep showing denied.
  • Gbenga B Ayannuga
    Gbenga B Ayannuga over 2 years
    i have try flutter clean is still not showing on the device....
  • Robouste
    Robouste over 2 years
    I'm sorry I can't help, I haven't work with Flutter since then