Reputation: 1948
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.
Upvotes: 1
Views: 6552
Reputation: 1357
You can also use https://github.com/dbaq/cordova-plugin-contacts-phone-numbers to retrieve only the contacts with at least one phone number.
Upvotes: 0
Reputation: 41
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" +
);
}
}
Upvotes: 4
Reputation: 2417
phoneNumbers 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.com/en/1.6.1/cordova_contacts_contacts.md.html#ContactField
Upvotes: 5