Open SCasarotto opened 4 years ago
You need to request the READ_CONTACTS permission using PermissionsAndroid if your targetSdkVersion > 22.
hi, import permision android
import {PermissionsAndroid} from 'react-native';
and use this two method
getPhoneNumber = async () => {
return selectContactPhone().then(selection => {
if (!selection) {
return null;
}
let {contact, selectedPhone} = selection;
console.log(
`Selected ${selectedPhone.type} phone number ${selectedPhone.number} from ${contact.name}`,
);
return selectedPhone.number;
});
}
requestContactPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_CONTACTS,
{
title: 'Allow Access Contact?',
message:
'allow this app to read contact information',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('granted');
this.getPhoneNumber();
} else {
console.log('denied');
}
} catch (err) {
console.warn(err);
}
}
and call from jsx
this.requestContactPermission();
have a nice day :D
thank you @GusNando for the explanation. in my Xiaomi Redmi 6, after popup permission show and click the Allow button, the code after await request permission is not excuted, so i can not get the granted value. How to fix it?
did you added <uses-permission android:name="android.permission.READ_CONTACTS" />
in android manifest? and can you share some of your code?
import {PermissionsAndroid} from 'react-native';
I am receiving an android permission error even though I add this
<uses-permission android:name="android.permission.READ_CONTACTS" />
to myAndroidManifest
. any guesses? Works just fine on iOS. Even tried thereact-native link
but that didn't seem to resolve it.