Scroll to top

How to get all contacts and count contact numbers from mobile in cordova?

Get  all contacts and count contact numbers from mobile in cordova.


document.addEventListener(“deviceready”, jaspreet, false);
function jaspreet() {
   //
   //
   // after deviceready
   //
   //
   navigator.contactsPhoneNumbers.list(function(contacts) {
      console.log(contacts.length + ‘ contacts found’);
  alert(contacts.length);
      for(var i = 0; i < contacts.length; i++) {
         console.log(contacts[i].id + ” – ” + contacts[i].displayName);
         for(var j = 0; j < contacts[i].phoneNumbers.length; j++) {
            var phone = contacts[i].phoneNumbers[j];
            console.log(“===> ” + phone.type + ”  ” + phone.number + ” (” + phone.normalizedNumber+ “)”);
document.getElementById(“names”).innerHTML +=phone.type + ”  ” + phone.number;
         }
      }
   }, function(error) {
      console.error(error);
   });
   
}

Leave a Reply

Your email address will not be published.