To create engaging applications with various contacts features, you must learn to access the address books in which the contacts are listed:
To get the default address book, use the getDefaultAddressBook() method of the ContactManager interface to retrieve the default address book as an AddressBook object:
var myAddressbook; /* Get the default address book */ myAddressbook = webapis.contact.getDefaultAddressBook();
To get all available address books, use the getAddressBooks() method. This method returns an array of AddressBook objects to the success event handler.
var addressBook; function addressBooksCB(addressBooks) { if (addressBooks.length > 0) addressBook = addressBooks[0]; console.log("The addressbook type is " + addressbook.type + " and name " + addressbook.name); } /* Get the list of available address books */ webapis.contact.getAddressBooks(addressBooksCB, errorCallback);
All available address books on the device are retrieved. You can use an AddressBook object name to select a specific address book from the array with the getAddressBook() method.