This feature enables your mobile application to create, remove, and search through contacts on the mobile device.
This feature is supported in the following platforms:
Execute the following command in your Cordova project directory:
Code Block |
---|
|
cordova plugin add cordova-plugin-contacts |
Code Block |
---|
|
// This function creates a new contact on the mobile device
this.fm.registerHandler("cbxclick", "CREATE",
function (fm, event, fieldName, value)
{
var params =
{
"displayName": "CT",
"firstName": "Canvas",
"lastName": "Technology",
"workNumber": "212-555-1234",
"mobileNumber": "917-555-5432",
"homeNumber": "2345234567"
};
var contact = canvas.env.contacts.create(params, onSuccess, onError);
});
// This function is executed when new contact is successfully created on the mobile device.
function onSuccess(success)
{
showAlert("saved" + success);
}
// This function is executed when new contact is not created on the mobile device.
function onError(err)
{
showAlert("not saved" + err);
}
|
Code Block |
---|
|
// This function picks a phone number from the contact on the mobile device.
this.fm.registerHandler("cbxclick", "PICK_PHONENO",
function (fm, event, fieldName, value)
{
canvas.env.contacts.pickPhoneNumbers(function (phoneNumber)
{
showAlert(phoneNumber);
}, function (err)
{
showAlert(err);
});
});
// This function picks a name from the contact on the mobile device.
this.fm.registerHandler("cbxclick", "PICK",
function (fm, event, fieldName, value)
{
canvas.env.contacts.pickContact(function (message)
{
showAlert(cbx.encode(message));
}, function (err)
{
showAlert(err);
});
});
|