联系人操作

联系人操作,create和find联系人
牛刀小试
创建联系人
查找联系人
通讯录选人
示例代码
//创建联系人,重复添加人会失败
function onSuccess(contact) {
    alert("Save Success");
};
function onError(contactError) {
    alert("Error = " + contactError.code);
};
var myContact = navigator.contacts.create({"displayName": "刘关羽"});
var phoneNumbers = [];
phoneNumbers[0] = new ContactField('mobile', '917-555-5432', true);
myContact.phoneNumbers = phoneNumbers;
myContact.note = "This contact has a note.";
myContact.save(onSuccess,onError);
//查找联系人
function onSuccess(contacts) {
    var names = "";
    for (var i = 0; i < contacts.length; i++) {
         names = contacts[i].displayName + "---" + contacts[i].phoneNumbers[0].value + "\n" +  names;
    };
     alert(names);
};
function onError(contactError) {
    alert('onError!');
};
// find all contacts with '刘' in any name field
var options = new ContactFindOptions();
options.filter="刘";
options.multiple=true; 
var fields = ["displayName", "name"];
navigator.contacts.find(fields, onSuccess, onError, options);