Flutter-permission-handler: Android Permission.storage.status never returns permanentlyDenied

Created on 14 Apr 2021  路  7Comments  路  Source: Baseflow/flutter-permission-handler

I It seems Permission.storage.status always returns .denied regardless of status. If I grant access, it will still say .denied, if I permanentlyDeny permission it still just says .denied.

After you "Files and Media" access a few times, Android will stop prompting the user for access to the storage. However, the status never changes from PermissionStatus.denied to PermissionStatus.permanentlyDenied.

So there is no way on Android to detect this scenario to let the user know they need to enable the permission in their app settings, and provide them a link.

android

Most helpful comment

I've contacted my colleague about this since I was able to also reproduce this same issue.

When requesting the status of a permission using Permission.x.status will always return a PermissionStatus.denied if you denied the permission mutlitple times or even if you click the 'Don't ask again' checkbox.
When requesting the status of a permission using Permission.x.request() it can either return a PermissionStatus.denied or a PermissionStatus.permanentlyDenied (depends on if you clicked the 'Don't ask again' checkbox or deny the permission a second time).

The reason is that on Android we can only determine whether permissions are permanently denied immediately after requesting permissions. That's because of how the status of a permission is being retrieved. When requesting the Permission.x.status Android's OS returns only a denied or granted so we can't determine if it's also PermissionStatus.permanentlyDenied.

A little bit more information and a code example on how to fix this problem can be found here.

I hope this will help, the issue will be closed for now, if anyone has questions please feel free to ask.

All 7 comments

I'm facing the same problem with Permission.camera. I'm using permission_handler 6.1.3, running on Android 8.1 (API 27).

Hi @m-j-g, I tested this on Android API level 27 and 30 (Android 8.1 and 11) using permission_handler ^6.1.3 running the example app provided by the plugin. But I cannot seem to duplicate the same behaviour.

Can you send me some more info about the problem? I would like to know on what Android device and which Android version you testes this, a flutter doctor -v, and which version of the plugin you used.

@maporcho I also can't seem to reproduce the same behaviour about the camera permission. I also tried using the example app provided by the plugin, using version 6.1.3 on Android 8.1 Pixel 3 emulator.

@m-j-g and @maporcho, I tested this using the example app as mentioned above here, if I click on the permission (whether it was the storage permission or the camera permission) it asked me to allow or deny the permission. When pressing deny, and clicking on the same permission again it asked me the same thing but now with an extra option called 'Don't ask again'. From this point on there are 3 possible states.

If clicking 'Don't ask again':
Permission status will be PermissionSatus.permanentlyDenied

If clicking deny:
Permission status will be PermissionStatus.denied

If clicking allow:
Permission status will be PermissionStatus.granted

So the way I tested it, the behaviour it showed was correct. I would like to know if updating to the newest version of the plugin helped, otherwise I would love to see some more information about the device and flutter doctor -v.

On the newest version there is one less problem but still the main issue. Using the new version permission_handler: ^7.1.0 on the Pixel3a running Android 11. Permission.storage.status never returns PermissionStatus.permanentlyDenied, but it does show PermissionStatus.granted now.

I have the same (or similar) problem:
while "await Permission.storage.request()" returns "PermissionStatus.permanentlyDenied" (which is correct)
any further request of "await Permission.storage.status" returns "PermissionStatus.denied" (which is wrong)

Same here. I have been testing on Samsung A21s and on Pixel 3a Emulator, both with Android 11 (SDK 30) with permission_handler ^7.1.0.
When calling await Permission.camera.status for the first time, after app install, I got PermissionStatus.denied status.
After clicking Deny and requesting camera status again, I got PermissionStatus.denied. So far, so good.
When requesting camera status second time, there is only Deny button, not Deny & Don't ask again button as it was on Android 10.
So, after pressing "Deny" button second time, and requesting camera status for the third time, camera status is still returning PermissionStatus.denied but await Permission.camera.request(); is returning PermissionStatus.permanentlyDenied.

Same problem. Testing on device Xiaomi Mi10 T Lite, Android 11 whit permission_handler ^7.1.0.

Code:
var status = await Permission.camera.status;
print(status);
if(status.isDenied){
await Permission.camera.request();
}
if(status.isPermanentlyDenied){
openAppSettings();
}
print(status);

Case:
When I reject it for the first time, I can request for the permission a second time, but if I reject it again, status.isDenied is always true, it is never PermanentlyDenied, and I can no longer request for it again.

I've contacted my colleague about this since I was able to also reproduce this same issue.

When requesting the status of a permission using Permission.x.status will always return a PermissionStatus.denied if you denied the permission mutlitple times or even if you click the 'Don't ask again' checkbox.
When requesting the status of a permission using Permission.x.request() it can either return a PermissionStatus.denied or a PermissionStatus.permanentlyDenied (depends on if you clicked the 'Don't ask again' checkbox or deny the permission a second time).

The reason is that on Android we can only determine whether permissions are permanently denied immediately after requesting permissions. That's because of how the status of a permission is being retrieved. When requesting the Permission.x.status Android's OS returns only a denied or granted so we can't determine if it's also PermissionStatus.permanentlyDenied.

A little bit more information and a code example on how to fix this problem can be found here.

I hope this will help, the issue will be closed for now, if anyone has questions please feel free to ask.

Was this page helpful?
0 / 5 - 0 ratings