cordova-plugin-contacts
cordova plugin contacts
cordova-plugin-contacts

cordova-plugin-contacts used for accessing device contacts, where you can create new contact, clone contact, search and retrieve contacts

Note: edit & delete is not possible

cordova plugin add cordova-plugin-contacts

Methods

  • navigator.contacts.create
  • navigator.contacts.find
  • navigator.contacts.pickContact

How to create New contact ?

syntax

var myContact = navigator.contacts.create({"displayName": "Test User"});
myContact.save();

navigator.contacts.create used for creating new contacts, you need to pass json objects inside the function, .save() used for save your created contact with device

Search contact ?

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

navigator.contacts.find() used for search contact with given field names

Example


// find all contacts with 'sundar' in any name field
var options      = new ContactFindOptions();
options.filter   = "sundar";
options.multiple = true;
options.desiredFields = [navigator.contacts.fieldType.id];
options.hasPhoneNumber = true;
var fields       = [navigator.contacts.fieldType.displayName, navigator.contacts.fieldType.name];
navigator.contacts.find(fields, onSuccess, onError, options);
function onSuccess(contacts) {
alert('Found ' + contacts.length + ' contacts.');
};
function onError(contactError) {
alert('onError!');
};

Pick Contact

navigator.contacts.pickContact used for open a contact picker, where you can pick for particular contact & retrieve information about the contact

navigator.contacts.pickContact(function(contact){
 console.log('The following contact has been selected:' + JSON.stringify(contact));
},function(err){
 console.log('Error: ' + err);
});
Sundaravel M

About the author: Hey! It's me sundar. (Yea, I'm the founder of codesundar.com). I'm a passionate computer programmer who loves modern web and mobile development. feel free to reach me : Facebook - Twitter - Google+