Search code examples
cordovacontacts

Cordova 3.5 ContactFindOption to search contact by phonenumber


I want to search contacts by phonenumber. I am using code:

 function onSuccess(contacts) {
    console.log(contacts)
};

function onError(contactError) {
    alert('onError!');
};

// find all contacts with given phone number
var options = new ContactFindOptions();
options.filter="9427831147";
options.multiple=false; 
var fields = ["phoneNumber"];
navigator.contacts.find(fields, onSuccess, onError, options);

I found that

filter: Property can only apply to the following: "firstName", "lastName", "nickname", "phoneNumber", "email", "address"

on http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html
I am not getting any result.
Anything I am missing?


Solution

  • On Adroid I tested successfully with onSuccess and fields placed differently, like this:

    navigator.contacts.find(onSuccess, onError, fields, options);
    

    Which contradicts the manual but it works.

    It is phoneNumbers with s in the end, not phoneNumber.