I am attempting to access a contact's phone number in PhoneGap "Cordova 1.6.1" and send messages to this number. I have been testing the application on the Android mobile platform and I am able to access the name of a contact using this function:
$('#contacts').append('<option value="'+contacts[i].name+'" >' + contacts[i].name.formatted + '</select>');
However, when I enter:
contacts[i].phoneNumbers.formatted
The output is Undefined.
What is the issue I am running into? How may I properly access a contact's phone number in a PhoneGap android application.
I am attempting to access a contact's phone number in PhoneGap "Cordova 1.6.1" and send messages to this number. I have been testing the application on the Android mobile platform and I am able to access the name of a contact using this function:
$('#contacts').append('<option value="'+contacts[i].name+'" >' + contacts[i].name.formatted + '</select>');
However, when I enter:
contacts[i].phoneNumbers.formatted
The output is Undefined.
What is the issue I am running into? How may I properly access a contact's phone number in a PhoneGap android application.
Share Improve this question edited May 1, 2012 at 13:47 Sana Joseph asked May 1, 2012 at 13:31 Sana JosephSana Joseph 1,9487 gold badges37 silver badges58 bronze badges3 Answers
Reset to default 5phoneNumbers is an array, so you need to index into it.
for (var j=0; j<contacts[i].phoneNumbers.length; j++) {
alert("Type: " + contacts[i].phoneNumbers[j].type + "\n" +
"Value: " + contacts[i].phoneNumbers[j].value + "\n" +
"Preferred: " + contacts[i].phoneNumbers[j].pref);
}
http://docs.phonegap./en/1.6.1/cordova_contacts_contacts.md.html#ContactField
check out if u'r phoneNumbers array is not null
something like this
if (contacts[i].phoneNumbers){
for (var j=0; j<contacts[i].phoneNumbers.length; j++) {
alert( " " + contacts[i].phoneNumbers[j].value + "\n" +
);
}
}
You can also use https://github./dbaq/cordova-plugin-contacts-phone-numbers to retrieve only the contacts with at least one phone number.