I want to display the list of contacts on my AVD but Im facing an error (I tried linking the package but it did nothing):
const [contact, setContact] = useState([]);
useEffect(() => {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
'title': 'Contacts',
'message': 'This app would like to view your contacts.'
}
).then(() => {
Contacts.getAll((err, contacts) => {
if (err === 'denied'){
// error
} else {
// contacts returned in Array
setContact(contacts);
console.log(contact);
}
})
})
.catch((err)=> {
console.log(err);
})
}, []);
I searched everywhere for a solution but there's nothing about this issue, thanks for helping me by advance.
The APIs has been updated in version 6. Changing from callback (version 5 uses callback) to promise worked for me. I mean change -
Contacts.getAll((err, contacts) => { });
to -
Contacts.getAll()
.then((contacts) => {
// work with contacts
})
.catch((e) => { //handle error })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With