react-native icon indicating copy to clipboard operation
react-native copied to clipboard

PermissionsAndroid request returns "never_ask_again" on popup dismiss

Open zoontek opened this issue 3 years ago • 16 comments

Description

On Android 11, dismissing the request permission popup by tapping outside of it or by pressing the hardware back button will result on a never_ask_again answer even if the permission is still requestable (it actually should be equal to denied then).

On this version, the "Never ask again" checkbox disappear. The user have to press "Deny" twice to achieve the same effect. See https://developer.android.com/about/versions/11/privacy/permissions#dialog-visibility.

PS: Dismissing the popup isn't the same as pressing the "Deny" button, since requesting the permission is possible after multiple (2+) popup dimiss.

I made a GIF to illustrate the issue:

Screen Recording 2020-10-11 at 19 11 46

React Native version:

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 2.07 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.8.0
    Yarn: 1.22.5
    npm: 6.14.8
    Watchman: 4.9.0
  Managers:
    CocoaPods: 1.9.3
  SDKs:
    iOS SDK:
      Platforms: iOS 14.0, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
    Android SDK:
      API Levels: 21, 28, 29, 30
      Build Tools: 27.0.3, 28.0.3, 29.0.1, 29.0.2, 29.0.3, 30.0.0, 30.0.2
      System Images: android-21 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: 21.3.6528147
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6821437
    Xcode: 12.0.1/12A7300
  Languages:
    Java: 1.8.0_265
    Python: 2.7.17
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: 0.63.3 => 0.63.3
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Try to request a permission on Android 11+
  2. Dismiss the request popup by tapping outside of it or by pressing the hardware back button
  3. The request resolves with never_ask_again

Expected Results

The permission is still requestable: It should resolves with denied

zoontek avatar Oct 11 '20 18:10 zoontek

Any updated on this issue ?

sanduluca avatar Aug 18 '21 13:08 sanduluca

I am also facing this issue...but I think this is an Android issue (not a React-Native one). These are my observations:

The documentation says that a permission request can be canceled (see here), in which case, the grantResults array will be empty. However, if you dismiss the permission system dialog by clicking outside, the request isn't canceled. Instead, it is considered as a denial (grantResults[0] is PackageManager.PERMISSION_DENIED).

And something even stranger: although it is considered a denial, activity.shouldShowRequestPermissionRationale() returns false.

We follow the rule that if a permission was denied and if shouldShowRequestPermissionRationale returned false, then this implies a NEVER_ASK_AGAIN. So the logic is correct.

Android needs to either:

  1. Return an empty grantResults array when you click outside the permission alert
  2. Make shouldShowRequestPermissionRationale return true after a clicked-outside-denial.

HectorRicardo avatar Sep 03 '21 01:09 HectorRicardo

I am also facing this issue...but I think this is an Android issue (not a React-Native one). These are my observations:

The documentation says that a permission request can be canceled (see here), in which case, the grantResults array will be empty. However, if you dismiss the permission system dialog by clicking outside, the request isn't canceled. Instead, it is considered as a denial (grantResults[0] is PackageManager.PERMISSION_DENIED).

And something even stranger: although it is considered a denial, activity.shouldShowRequestPermissionRationale() returns false.

We follow the rule that if a permission was denied and if shouldShowRequestPermissionRationale returned false, then this implies a NEVER_ASK_AGAIN. So the logic is correct.

Android needs to either:

  1. Return an empty grantResults array when you click outside the permission alert
  2. Make shouldShowRequestPermissionRationale return true after a clicked-outside-denial.

Then how is that in https://github.com/zoontek/react-native-permissions this problem is not present/was solved ?

sanduluca avatar Sep 03 '21 06:09 sanduluca

I haven't looked closely at zoontek's implementation, but from what I saw, he's using a helper flag to check if the rationale was previously shown.

I don't like that approach because you have to consider many edge cases: what if you install an app, then immediately deny permissions from the settings without ever opening it, open it for the first time, and then request for permissions? Because of the boolean flag, now this returns "DENIED" instead of "NEVER_ASK_AGAIN".

HectorRicardo avatar Sep 03 '21 17:09 HectorRicardo

@HectorRicardo Indeed. It's far from perfect, but Android 11+ is completely broken. What a shame.

zoontek avatar Sep 03 '21 17:09 zoontek

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Jan 09 '22 12:01 stale[bot]

I'm also facing the exact same problem. Any solution for this?

AmeerAsif777 avatar Apr 01 '22 14:04 AmeerAsif777

I am not even getting popup can anyone know why??

Nilesh8451 avatar Dec 11 '22 08:12 Nilesh8451

I am not even getting popup can anyone know why??

same problem for me

rosjerry avatar May 02 '23 10:05 rosjerry

Same problem here. I am asking multiple permissions, CAMERA permission pop-up is opening and working fine, but for WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions pop-up is not even opening and returning never_ask_again. I think the issue is specific to devices because on majority of devices functionality is working, but on emulator and some devices, application is not functional due to this issue.

vatsal65 avatar May 12 '23 13:05 vatsal65

I am also facing this, I think it is specific to devices. In my case even the request permission pop is also not showing. I am facing this issue on android above 11.

neon010 avatar May 17 '23 16:05 neon010

I am also facing this, I think it is specific to devices. In my case even the request permission pop is also not showing. I am facing this issue on android above 11.

Same here

qasimali09 avatar Jun 01 '23 13:06 qasimali09

I am also facing this, I think it is specific to devices. In my case even the request permission pop is also not showing. I am facing this issue on android above 11.

Faced the same issue, found this: https://stackoverflow.com/a/73630987

RuarddeBruyn avatar Jun 21 '23 10:06 RuarddeBruyn

From the Stackoverflow comment: we only need to ask for READ and WRITE Permission on Android API lower or equal 29.

However, still I get rejected without a popup opening on Android Api 30, 31, 32. 33 is working as it should when I set the targetSDK to 33 in the gradle.

Why is it simply rejecting the storage permissions for those three api levels inbetween?

Maxeeezy avatar Aug 10 '23 10:08 Maxeeezy

I solved this by setting the Android Manifest:

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion" />

until 32 it would prompt and ask for permission now.

I tested from 32 down to 29, backward compatibility is given.

Maxeeezy avatar Aug 10 '23 14:08 Maxeeezy

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 01 '24 05:05 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar May 09 '24 05:05 github-actions[bot]