Please provide the following:
- SDK Version:
“sdkVersion”: “35.0.0”,
- Platforms(Android/iOS/web/all):
iOS - code works fine
Android - code throws an error
The following code in an app adds a new phone number to a contact record on the device by adding another phoneNumber object to the phoneNumber array on the contact record. It works fine in iOS on an actual device and in an iOS simulator but when I build an apk file (with the permissions below) and install the App on an Android phone it fails to update the contact record and instead it throws an error (see below).
Here are the permissions in app.json
"permissions": [
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.CAMERA",
"android.permission.VIBRATE",
"android.permission.READ_CONTACTS",
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.READ_PHONE_STATE",
"android.permission.WRITE_CONTACTS",
"android.permission.WAKE_LOCK",
"android.permission.WRITE_EXTERNAL_STORAGE",
"com.anddoes.launcher.permission.UPDATE_COUNT",
"com.android.launcher.permission.INSTALL_SHORTCUT",
"com.google.android.c2dm.permission.RECEIVE",
"com.google.android.gms.permission.ACTIVITY_RECOGNITION",
"com.google.android.providers.gsf.permission.READ_GSERVICES",
"com.htc.launcher.permission.READ_SETTINGS",
"com.htc.launcher.permission.UPDATE_SHORTCUT",
"com.majeur.launcher.permission.UPDATE_BADGE",
"com.sec.android.provider.badge.permission.READ",
"com.sec.android.provider.badge.permission.WRITE",
"com.sonyericsson.home.permission.BROADCAST_BADGE"
],
Here is the code. It’s important to note that contactRecord is saved in React State and it’s just a copy of the native contact record with no changes.
const { editPhoneNumberValue, editPhoneNumberLabel, contactRecord } = this.state;
try {
let contact = await Contacts.getContactByIdAsync(contactRecord.id);
let _phoneDigits = editPhoneNumberValue.replace(/[\W_]+/g, '');
let _label = editPhoneNumberLabel;
if (Platform.OS === 'android') {
contact.phoneNumbers.push({
isPrimary: 0,
label: _label,
number: editPhoneNumberValue,
type: '2'
});
} else {
contact.phoneNumbers.push({
countryCode: 'us',
digits: _phoneDigits,
label: _label,
number: editPhoneNumberValue
});
}
Contacts.updateContactAsync(contact)
.then(async response => {
// 1. Get the updated contact record and do stuff with it...update state, etc
})
.catch(error => {
// 2. Catch the error below here. The then above does not get executed.
});
} catch (error) {
...another error catch point that is not being triggered.
}
Here is part of the error message thrown by updateContactAsync in Sentry. It’s getting truncated but even when I read the rest of the error it’s pretty useless and doesn’t tell me anything:
{{"framesToPop":1,"nativeStackAndroid":[{"methodName":"readExceptionWithOperationApplicationExceptionFromParcel","lineNumber":156,"file":"DatabaseUtils.java"},{"methodName":"applyBatch","lineNumber":522,"file":"ContentProviderNative.java"},...