请求相机权限时,在android崩溃时本机反应原生

时间:2017-12-14 11:27:19

标签: android react-native permissions

当我请求允许在本机中使用相机时,我的手机(Android 8.1.0)一直崩溃。我在Android Manifest中使用android:targetSdkVersion="25"

componentDidMount(){
(async () => {
    await this.requestCameraPermission();
})();}




  async 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)
  }
}

0 个答案:

没有答案