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

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM