question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PermissionsAndroid] request is not prompting and always return true

See original GitHub issue

Description

I want to use the camera in my react-native application on Android. For this, I’m using the Camera from https://github.com/lwansbrough/react-native-camera.

So, in order to this, i’m using PermissionsAndroid to make sure that the user has the access to the camera. Here comes my problem.

I’m using the code from the doc (here https://facebook.github.io/react-native/docs/permissionsandroid.html) to do the request permission on camera and I’m having an issue with this as it never asks me to allow the camera and always returns true, even if I disable the camera permission on my device.

Here is the scenario when camera permission access is granted :

17474142_10213255883420181_780649716_o 17455229_10213255883380180_703171875_o

Here is the scenario when camera permission access is not granted :

17475238_10213255884100198_166958326_o 17475223_10213255884140199_1657109422_o

Reproduction

What I’m doing is simply this :

export async function requestCameraPermission() {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        'title': 'Cool Photo App Camera Permission',
        'message': 'Cool Photo App needs access to your camera ' +
                   'so you can take awesome pictures.'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera")
    } else {
      console.log("Camera permission denied")
    }
  } catch (err) {
    console.warn(err)
  }
}
  async componentWillMount() {
    await requestCameraPermission() // which always returns "You can use the camera" even if I disable camera permission access on my device
  }

Additional Information

  • React Native version: 0.40
  • Platform: Android 7.1.1
  • Development Operating System: Linux (Ubuntu 16.04)
  • Dev tools: android:minSdkVersion=“16” android:targetSdkVersion=“23”

I’m also experiencing this issue using https://github.com/yonahforst/react-native-permissions/ : https://github.com/yonahforst/react-native-permissions/issues/86

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:17

github_iconTop GitHub Comments

34reactions
daniel90danielcommented, Apr 4, 2017

Hi, I had the same problem. I solved it by changing the targetSdkVersion ( same to compileSdkVersion, in my case 23) in android/app/build.gradle.

4reactions
Blapicommented, Apr 4, 2017

Much thanks @daniel90daniel !!!

I did what you did and this is now working perfectly !

If some guys are experimenting the same issue, be careful because as I said in my issue, my dev tools are android:minSdkVersion=“16” android:targetSdkVersion=“23” BUT those are the infos in my AndroidManifest.xml… in my android/app/build.gradle, the targetSdkVersion was 22 and not 23, and putting it to 23, as @daniel90daniel said, makes it work for me now !

Read more comments on GitHub >

github_iconTop Results From Across the Web

PermissionsAndroid - React Native
However, "dangerous" permissions require a dialog prompt. ... always result to true and request should always resolve to PermissionsAndroid.
Read more >
PermissionsAndroid - React Native
However, "dangerous" permissions require a dialog prompt. ... always result to true and request should always resolve to PermissionsAndroid.
Read more >
Request location permissions - Android Developers
Overview · Standalone apps · Authentication · Request permissions · Detect location ... Tag expressions · Language settings · Always-on in Watch Face...
Read more >
PermissionsAndroid is not showing up in React Native app
Your userdefined Text to request Permission you've added: ... The optional rationale argument will show a dialog prompt only if necessary ...
Read more >
react native - PermissionsAndroid not returning anything
Hello I'm trying to use PermissionsAndroid to ask my user to use the Camera. ... It works well and asking the Permission to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found