user2993925 user2993925 - 4 months ago 16
Android Question

cordova contact plugins - emails null

I'm using "Cordova" to create application for IOS and Android.
And i need to accessed the contacts of the device. I use for that the plugin "org.apache.cordova.contacts".

Here are the part of the code i use to do that, and i get a response...

function ContactsCtrl($scope){
var options = new ContactFindOptions();
options.multiple = true;
options.filter = "Benoit";
var fields = ["displayName", "name", "nickname "];
navigator.contacts.find(fields, onSuccess, onError, options);
}

function onSuccess(contacts) {
var ret = '';
for (var i = 0; i < contacts.length; i++) {
for(x in contacts[i]){
ret += x+' :'+contacts[i][x]+"\n";
}
}
$('#resultContact').html(html);
}


And the response :

rawId :null
displayName :Nasher
name :[object Object]
nickname :null
phoneNumbers :null
emails :null
...
...


The problem :
"emails" field and "phoneNumbers" field are always empty (on android and on iOs) however they exist in the "contacts book"

Anybody have a idee why ?

Answer

The phonegap docs say:

contactFields: Contact fields to use as a search qualifier. The resulting Contact object only features values for these fields. (DOMString[]) [Required]

You don't add the emails and phoneNumbers field to your fields array. Try:

var fields = ["displayName", "name", "nickname", "emails", "phoneNumbers"];