最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I access a contact's phone number in a PhoneGap running on Android - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 5

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./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.

发布评论

评论列表(0)

  1. 暂无评论