react-native: [PermissionsAndroid] request is not prompting and always return true
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 :
Here is the scenario when camera permission access is not granted :
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 17
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.
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 !
You do not believe me, hey, what am I doing wrong? Gentlemen, I did not lie to you 😭😭😭😭
Oh ok I see @TrustTheBoy thanks for the explanation it’s crystal clear 👍👍
@aronse I just want to say android 6.0 before the device how to detect, and no other meaning