Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permission for camera not working in android app React Native

Tags:

react-native

No message is being prompted. It just denies the permission. I have also made same, the targetedSdk version and compilesdk version.

I've made same, the targetedSdk version and compilesdk version.

My function on 'Request' Button:

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) {
    alert("You can use the camera")
  } else if (PermissionsAndroid.RESULTS.DENIED){
    console.log("Camera permission denied")
  }
} catch (err) {
  console.warn(err)
}

I expect a prompt message and by tapping 'Yes', it must grant the permission but no prompt is shown.

like image 325
Mubasher Ahmad Avatar asked Dec 24 '18 07:12

Mubasher Ahmad


1 Answers

You need to also add in the permissions to the Manifest file for Android or the pList in iOS.

For Android:

Add this to your Manifest:

<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />

https://developer.android.com/reference/android/hardware/Camera

For iOS

Take a look here: iOS 10 - Changes in asking permissions of Camera, microphone and Photo Library causing application to crash

like image 98
JRK Avatar answered Oct 04 '22 23:10

JRK