React-native-permissions: Android Do not ask again value is wrong (Should be 'blocked' but is returned 'denied')

Created on 28 Feb 2020  路  17Comments  路  Source: zoontek/react-native-permissions

Bug

Do not ask again should returns blocked value if it is selected, but returns denied instead.

Environment info

react: 16.8.3 => 16.8.3
react-native: 0.59.9 => 0.59.9

Library version: ^2.0.9

Describe what you expected to happen:

  1. Asking Android's permission to use the Microphone.
  2. Select do not ask me again and then refuse, which is the only option left.
  3. check(permission) should return Blocked but returns Denied

Reproducible sample code

const toggleRecording = async () => {
    if (recording) {
      return setRecording(!recording)
    }

    const permission = await check(permissionPerPlatform)

    if (permission === RESULTS.DENIED) {
      return askRecordAudioPermission();
    }

    if (permission === RESULTS.BLOCKED) {
      return (
        Alert.alert(
          I18n.t("sharedMessaging.audio.permissions.title"),
          I18n.t("sharedMessaging.audio.permissions.text"),
          [
            { text: I18n.t("sharedMessaging.audio.permissions.action") },
          ],
          { cancelable: false },
        )
      );
    }

    setRecording(!recording)
  };

  const askRecordAudioPermission = async () => await request(permissionPerPlatform);

bug

All 17 comments

@asavardplante Could you provide more informations (Android version, device, etc.)? Thanks!

@zoontek Yes thanks for answering! The device that I'm testing on is an LG-G4, running on Android 6.0. I didn't change anything manually on the device that could have had an impact on the current problem.

Edit : I also tested on a Moto G5s running on Android 8.1.0 and it stills return denied instead of blocked

I'm also seeing this error on a Nexus 6P android 8.1.0, security patch dec. 5th, 2018

React native version 61.5, library version 2.0.9

Issue happens on both Camera and Microphone permissions; I haven't tried other permission types

@asavardplante @owattenmaker Could you try the 2.1.0 branch? https://github.com/react-native-community/react-native-permissions/tree/2.1.0 It should be fixed.

Hi @zoontek I'm also having this issue. I've just tried with that branch but i'm still getting denied instead of blocked when checking the status.

@alvaro-87 You first receive the "blocked" value then a "denied"? Using each time RNPermissions to request it? I currently can't reproduce it.

@zoontek I've kept testing a bit more and realized that while i was checking the permissions status with RNPermissions, it was the RNCamera from react-native-camera the one that was requesting the permission, and setting the wrong value.

I tested requesting the permission with RNPermissions and i can confirm that it worked fine for me (with both, this branch and master).

@asavardplante @owattenmaker Could you confirm if you have the same scenario i have or if you were indeed prompting the request with RNPermisssions when recreating the issue?

Hey! I'm correctly using the request() and check() from RNPermissions, but sadly the branch still returns denied when I log the permission after using check().

@owattenmaker Did it work for you?

@asavardplante Can you give your current versions for:

buildToolsVersion
minSdkVersion
compileSdkVersion
targetSdkVersion
supportLibVersion

@zoontek

buildToolsVersion = 28.0.0
minSdkVersion = 19
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = 28.0.0

@asavardplante Nothing abnormal here. Can you try:

React.useEffect(() => { // or componentDidMount
  const test = async () => {
    const firstCheckResult = await check(PERMISSIONS.ANDROID.RECORD_AUDIO);
    const requestResult = await request(PERMISSIONS.ANDROID.RECORD_AUDIO);
    const secondCheckResult = await check(PERMISSIONS.ANDROID.RECORD_AUDIO);

    console.log({ firstCheckResult, requestResult, secondCheckResult });
  };

  test();
}, []);

And confirm that it will log:

{ firstCheckResult: "denied", requestResult: "denied", secondCheckResult: "denied" }

Then, on a second app run, as you can check Never ask again:

{ firstCheckResult: "denied", requestResult: "blocked", secondCheckResult: "blocked" }

Also, did you set the use-permission tag inside your AndroidManifest.xml? Like in the example file.

If all of this still fail, try to setup a new app with the latest version of React Native (as the android part of this module is just a proxy over the main feature of PermissionAndroid)

Same issue.

Update:
I use lib-jitsi-meet and react-native-webrtc, when I open the camera, request of permission will be invoked by lib-jitsi-meet. So if I want the value return to BLOCKED not DENIED, I should also use this lib to request the permission in this case.

Yes. On Android, no API exists to know if we can request the permission so this library save blocked one in app storage. If you request it with something else, it can't know.

@zoontek I tested your code and I noticed that the secondCheckResult seems to never resolve on my end(if I log firstCheckResult / requestResult after they are called, I can see the logs for them only). I'm not sure what could be the cause but maybe it's the reason why blocked is never returned...

@asavardplante Can you try with a fresh project and RN 0.61?

Same issue.
Device: Xiaomi Redmi Note 7 (Android 10)
react-native: 0.63.3
react: 16.13.1
react-native-permissions: 3.0.1

check(PERMISSIONS.ANDROID.WRITE_EXTERNAL_STORAGE)
.then((result) => {
console.log(result)
})

result returned "denied" after choosing "do not ask again"

Any solution? Thank you.

Was this page helpful?
0 / 5 - 0 ratings