flutter-permission-handler
flutter-permission-handler copied to clipboard
Android - Permissions never asked
My app ask for permissions if the device or emulator are running Android 10 but if I try to run it in Android 11, the permissions are never asked for.
Can you provide more information? Which permissions are you requesting? What did you configure in your AndroidManifest.xml file?
Location (access background/foreground location), storage, camera, contacts, and I have configured the right permissions in the AndroidManifest. What I could see is, before the version 9.0.0 of this package, the multiple request permissions works until Android 10, but not else since version >= 9.0.0 of this package. It's related to https://github.com/Baseflow/flutter-permission-handler/issues/785.
// This won't work if the package version is >= 9.0.0
statuses = await [
Permission.storage,
Permission.contacts,
Permission.phone,
Permission.locationAlways,
].request();
So, for the version >= 9.0.0 I have to ask for individual permissions:
if (await Permission.storage.request().isDenied) {
await Permission.storage.request();
}
if (await Permission.contacts.request().isDenied) {
await Permission.contacts.request();
}
P.S: I edited the title because I saw it's not related actually with the OS version.
I have the same issue with Android 10, the app works well on Android 12 though.
This might help https://www.youtube.com/watch?v=uMvGpBOT0ZY
Hi @neoacevedo, thank you for filing this issue!
I have dug into the issue today and figured out the cause of the problem.
The issue is that you are requesting Permission.locationAlways. Referencing the README:
The locationAlways permission can not be requested directly, the user has to request the locationWhenInUse permission first. Accepting this permission by clicking on the 'Allow While Using App' gives the user the possibility to request the locationAlways permission. This will then bring up another permission popup asking you to Keep Only While Using or to Change To Always Allow.
To achieve your desired behavior, you could change the code to:
statuses = await [
Permission.storage,
Permission.contacts,
Permission.phone,
Permission.locationWhenInUse,
].request().then((_) => Permission.locationAlways.request());
This will ensure that Permission.locationWhenInUse is requested before Permission.locationAlways.
Please note that Permission.storage will no longer work starting with Android 13 (API 33). See #955 for more information.
I hope this answer covers any questions you might have regarding the topic. I will mark this issue as resolved. If you have follow-up questions, or suggestions on how we can improve our documentation to make this use case more clear, feel free to open up a new issue!