Android: requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

在安卓上使用组件react-native-contacts报错,是需要添加联系人的时候,说是权限问题,配置了manifest文件后依然不起效果,

 

解决方法:

  在需要引入react-native-contacts组件的页面,添加如下代码

 componentDidMount = () => {
        //Checking for the permission just after component loaded
        async function requestCameraPermission() {
            try {
                const granted = await PermissionsAndroid.request(
                    PermissionsAndroid.PERMISSIONS.WRITE_CONTACTS,{
                        'title': 'AndoridPermissionExample App Camera Permission',
                        'message': 'AndoridPermissionExample App needs access to your camera '
                    }
                )
                if (granted === PermissionsAndroid.RESULTS.GRANTED) {
                    //To Check, If Permission is granted
                    alert("You can use the 通讯录");
                } else {
                    alert("CAMERA permission denied");
                }
            } catch (err) {
                alert("err",err);
                console.warn(err)
            }
        }
        if (Platform.OS === 'android') {
            //Calling the permission function
            requestCameraPermission();
        }else{
            alert('IOS device found');
        }
    }

  

 

上一篇:wampserver2.5局域网公网IP访问配置


下一篇:【12c】OCP 062近期新出现的考试原题-第28题