WARNING: Collection and use of contact data raises
important privacy issues. Your app's privacy policy should discuss
how the app uses contact data and whether it is shared with any other
parties. Contact information is considered sensitive because it
reveals the people with whom a person communicates. Therefore, in
addition to the app's privacy policy, you should strongly consider
providing a just-in-time notice before the app accesses or uses
contact data, if the device operating system doesn't do so
already. That notice should provide the same information noted above,
as well as obtaining the user's permission (e.g., by presenting
choices for OK and No Thanks). Note that some app
marketplaces may require the app to provide a just-in-time notice and
obtain the user's permission before accessing contact data. A
clear and easy-to-understand user experience surrounding the use of
contact data helps avoid user confusion and perceived misuse of
contact data. For more information, please see the Privacy Guide.

iOS Quirks

Since iOS 10 it's mandatory to add a NSContactsUsageDescription entry in the info.plist.

NSContactsUsageDescription describes the reason that the app accesses the user’s contacts. When the system prompts the user to allow access, this string is displayed as part of the dialog box. To add this entry you can pass the variable CONTACTS_USAGE_DESCRIPTION on plugin install.

If you don't pass the variable, the plugin will add an empty string as value.

Firefox OS Quirks

Create www/manifest.webapp as described in
Manifest Docs.
Add relevant permisions.
There is also a need to change the webapp type to "privileged" - Manifest Docs.
WARNING: All privileged apps enforce Content Security Policy which forbids inline script. Initialize your application in another way.

"type":"privileged","permissions":{"contacts":{"access":"readwrite","description":"Describe why there is a need for such permission"}}

Windows Quirks

Prior to Windows 10: Any contacts returned from find and pickContact methods are readonly, so your application cannot modify them.
find method available only on Windows Phone 8.1 devices.

Windows 10 and above: Contacts may be saved and will be saved to app-local contacts storage. Contacts may also be deleted.

Windows 8 Quirks

Windows 8 Contacts are readonly. Via the Cordova API Contacts are not queryable/searchable, you should inform the user to pick a contact as a call to contacts.pickContact which will open the 'People' app where the user must choose a contact.
Any contacts returned are readonly, so your application cannot modify them.

navigator.contacts

Methods

navigator.contacts.create

navigator.contacts.find

navigator.contacts.pickContact

Objects

Contact

ContactName

ContactField

ContactAddress

ContactOrganization

ContactFindOptions

ContactError

ContactFieldType

navigator.contacts.create

The navigator.contacts.create method is synchronous, and returns a new Contact object.

This method does not retain the Contact object in the device contacts
database, for which you need to invoke the Contact.save method.

Supported Platforms

Android

BlackBerry 10

Firefox OS

iOS

Windows Phone 8

Example

varmyContact=navigator.contacts.create({"displayName":"Test User"});

navigator.contacts.find

The navigator.contacts.find method executes asynchronously, querying the
device contacts database and returning an array of Contact objects.
The resulting objects are passed to the contactSuccess callback
function specified by the contactSuccess parameter.

The contactFields parameter specifies the fields to be used as a
search qualifier. A zero-length contactFields parameter is invalid and results in
ContactError.INVALID_ARGUMENT_ERROR. A contactFields value of
"*" searches all contact fields.

The contactFindOptions.filter string can be used as a search
filter when querying the contacts database. If provided, a
case-insensitive, partial value match is applied to each field
specified in the contactFields parameter. If there's a match for
any of the specified fields, the contact is returned. Use contactFindOptions.desiredFields
parameter to control which contact properties must be returned back.

Supported values for both contactFields and contactFindOptions.desiredFields parameters are enumerated in ContactFieldType object.

Parameters

contactFields: Contact fields to use as a search qualifier. (DOMString[]) [Required]

contactSuccess: Success callback function invoked with the array of Contact objects returned from the database. [Required]

desiredFields: Contact fields to be returned back. If specified, the resulting Contact object only features values for these fields. (DOMString[]) [Optional]

hasPhoneNumber(Android only): Filters the search to only return contacts with a phone number informed. (Boolean) (Default: false)

Supported Platforms

Android

BlackBerry 10

Firefox OS

iOS

Windows Phone 8

Windows (Windows Phone 8.1 and Windows 10)

Example

functiononSuccess(contacts){alert('Found '+contacts.length+' contacts.');};functiononError(contactError){alert('onError!');};// find all contacts with 'Bob' in any name fieldvaroptions=newContactFindOptions();options.filter="Bob";options.multiple=true;options.desiredFields=[navigator.contacts.fieldType.id];options.hasPhoneNumber=true;varfields=[navigator.contacts.fieldType.displayName,navigator.contacts.fieldType.name];navigator.contacts.find(fields,onSuccess,onError,options);

Windows Quirks

__contactFields__ is not supported and will be ignored. find method will always attempt to match the name, email address, or phone number of a contact.

navigator.contacts.pickContact

The navigator.contacts.pickContact method launches the Contact Picker to select a single contact.
The resulting object is passed to the contactSuccess callback
function specified by the contactSuccess parameter.

Supported Platforms

Example

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

Android Quirks

This plugin launches an external Activity for picking contacts. See the
Android Lifecycle Guide
for an explanation of how this affects your application. If the plugin returns
its result in the resume event, then you must first wrap the returned object
in a Contact object before using it. Here is an example:

Contact

The Contact object represents a user's contact. Contacts can be
created, stored, or removed from the device contacts database.
Contacts can also be retrieved (individually or in bulk) from the
database by invoking the navigator.contacts.find method.

NOTE: Not all of the contact fields listed above are supported on
every device platform. Please check each platform's Quirks section
for details.

Properties

id: A globally unique identifier. (DOMString)

displayName: The name of this Contact, suitable for display to end users. (DOMString)

name: An object containing all components of a persons name. (ContactName)

nickname: A casual name by which to address the contact. (DOMString)

phoneNumbers: An array of all the contact's phone numbers. (ContactField[])

emails: An array of all the contact's email addresses. (ContactField[])

addresses: An array of all the contact's addresses. (ContactAddress[])

ims: An array of all the contact's IM addresses. (ContactField[])

organizations: An array of all the contact's organizations. (ContactOrganization[])

birthday: The birthday of the contact. (Date)

note: A note about the contact. (DOMString)

photos: An array of the contact's photos. (ContactField[])

categories: An array of all the user-defined categories associated with the contact. (ContactField[])

urls: An array of web pages associated with the contact. (ContactField[])

Methods

clone: Returns a new Contact object that is a deep copy of the calling object, with the id property set to null.

remove: Removes the contact from the device contacts database, otherwise executes an error callback with a ContactError object.

save: Saves a new contact to the device contacts database, or updates an existing contact if a contact with the same id already exists.

Supported Platforms

Amazon Fire OS

Android

BlackBerry 10

Firefox OS

iOS

Windows Phone 8

Windows

Save Example

functiononSuccess(contact){alert("Save Success");};functiononError(contactError){alert("Error = "+contactError.code);};// create a new contact objectvarcontact=navigator.contacts.create();contact.displayName="Plumber";contact.nickname="Plumber";// specify both to support all devices// populate some fieldsvarname=newContactName();name.givenName="Jane";name.familyName="Doe";contact.name=name;// save to devicecontact.save(onSuccess,onError);

FirefoxOS Quirks

iOS Quirks

Windows Quirks

ContactError

The ContactError object is returned to the user through the
contactError callback function when an error occurs.

Properties

code: One of the predefined error codes listed below.

Constants

ContactError.UNKNOWN_ERROR (code 0)

ContactError.INVALID_ARGUMENT_ERROR (code 1)

ContactError.TIMEOUT_ERROR (code 2)

ContactError.PENDING_OPERATION_ERROR (code 3)

ContactError.IO_ERROR (code 4)

ContactError.NOT_SUPPORTED_ERROR (code 5)

ContactError.OPERATION_CANCELLED_ERROR (code 6)

ContactError.PERMISSION_DENIED_ERROR (code 20)

ContactField

The ContactField object is a reusable component that represents
contact fields generically. Each ContactField object contains a
value, type, and pref property. A Contact object stores
several properties in ContactField[] arrays, such as phone numbers
and email addresses.

In most instances, there are no pre-determined values for a
ContactField object's type attribute. For example, a phone
number can specify type values of home, work, mobile,
iPhone, or any other value that is supported by a particular device
platform's contact database. However, for the Contactphotos
field, the type field indicates the format of the returned image:
url when the value attribute contains a URL to the photo
image, or base64 when the value contains a base64-encoded image
string.

Properties

type: A string that indicates what type of field this is, home for example. (DOMString)

value: The value of the field, such as a phone number or email address. (DOMString)

pref: Set to true if this ContactField contains the user's preferred value. (boolean)

Android 2.X Quirks

BlackBerry 10 Quirks

name: Partially supported. The first organization name is stored in the BlackBerry company field.

department: Not supported, returning null.

title: Partially supported. The first organization title is stored in the BlackBerry jobTitle field.

Firefox OS Quirks

pref: Not supported

type: Not supported

department: Not supported

Fields name and title stored in org and jobTitle.

iOS Quirks

pref: Not supported on iOS devices, returning false.

type: Not supported on iOS devices, returning null.

name: Partially supported. The first organization name is stored in the iOS kABPersonOrganizationProperty field.

department: Partially supported. The first department name is stored in the iOS kABPersonDepartmentProperty field.

title: Partially supported. The first title is stored in the iOS kABPersonJobTitleProperty field.

Windows Quirks

pref: Not supported, returning false.

type: Not supported, returning null.

ContactFieldType

The ContactFieldType object is an enumeration of possible field types, such as 'phoneNumbers' or 'emails', that could be used to control which contact properties must be returned back from contacts.find() method (see contactFindOptions.desiredFields), or to specify fields to search in (through contactFields parameter). Possible values are: