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