license: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contains properties that describe a contact, such as a user's personal or business contact.
null
.ContactError
object if the removal is unsuccessful.The Contact
object represents a user contact. Contacts can be created, saved to, or removed from the device contacts database. Contacts can also be retrieved (individually or in bulk) from the database by invoking the contacts.find
method.
Note: Not all of the above contact fields are supported on every device platform. Please check each platform's Quirks section for information about which fields are supported.
function onSuccess(contact) { alert("Save Success"); }; function onError(contactError) { alert("Error = " + contactError.code); }; // create a new contact object var contact = navigator.contacts.create(); contact.displayName = "Plumber"; contact.nickname = "Plumber"; //specify both to support all devices // populate some fields var name = new ContactName(); name.givenName = "Jane"; name.familyName = "Doe"; contact.name = name; // save to device contact.save(onSuccess,onError);
// clone the contact object var clone = contact.clone(); clone.name.givenName = "John"; console.log("Original contact name = " + contact.name.givenName); console.log("Cloned contact name = " + clone.name.givenName);
function onSuccess() { alert("Removal Success"); }; function onError(contactError) { alert("Error = " + contactError.code); }; // remove the contact from the device contact.remove(onSuccess,onError);
<!DOCTYPE html> <html> <head> <title>Contact Example</title> <script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script> <script type="text/javascript" charset="utf-8"> // Wait for Cordova to load // document.addEventListener("deviceready", onDeviceReady, false); // Cordova is ready // function onDeviceReady() { // create var contact = navigator.contacts.create(); contact.displayName = "Plumber"; contact.nickname = "Plumber"; //specify both to support all devices var name = new ContactName(); name.givenName = "Jane"; name.familyName = "Doe"; contact.name = name; // save contact.save(onSaveSuccess,onSaveError); // clone var clone = contact.clone(); clone.name.givenName = "John"; console.log("Original contact name = " + contact.name.givenName); console.log("Cloned contact name = " + clone.name.givenName); // remove contact.remove(onRemoveSuccess,onRemoveError); } // onSaveSuccess: Get a snapshot of the current contacts // function onSaveSuccess(contact) { alert("Save Success"); } // onSaveError: Failed to get the contacts // function onSaveError(contactError) { alert("Error = " + contactError.code); } // onRemoveSuccess: Get a snapshot of the current contacts // function onRemoveSuccess(contacts) { alert("Removal Success"); } // onRemoveError: Failed to get the contacts // function onRemoveError(contactError) { alert("Error = " + contactError.code); } </script> </head> <body> <h1>Example</h1> <p>Find Contacts</p> </body> </html>
null
.null
.null
.null
unless there is no ContactName specified. If there is no ContactName, then composite name, nickame or "" is returned for displayName, respectively.null
.