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');
        }
    }

  

原文地址:https://www.cnblogs.com/lude1994/p/11017610.html