Reputation: 3680
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.
Upvotes: 9
Views: 31031
Reputation: 410
add this
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Upvotes: 1
Reputation: 3680
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.
Upvotes: 13
Reputation: 4741
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.
Upvotes: 4
Reputation: 126914
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.
Upvotes: 2