© 2009 OMTP Ltd. All rights reserved. OMTP and OMTP BONDI are registered trademarks of OMTP Ltd.
This module provides access to both SIM and phone based contacts.
AddressBookArray
ContactsArray
ContactArraySuccessCallback
ContactManager
AddressBook
Contact
| Interface | Method |
|---|---|
| ContactArraySuccessCallback | void onSuccess(ContactsArray contacts) |
| ContactManager | AddressBookArray getAddressBooks() |
| AddressBook | Contact createContact(Map options) PendingOperation addContact(SuccessCallback successCallback, ErrorCallback errorCallback, Contact contact) PendingOperation updateContact(SuccessCallback successCallback, ErrorCallback errorCallback, Contact contact) PendingOperation deleteContact(SuccessCallback successCallback, ErrorCallback errorCallback, Contact contact) PendingOperation deleteAllContacts(SuccessCallback successCallback, ErrorCallback errorCallback) PendingOperation findContacts(ContactArraySuccessCallback successCallback, ErrorCallback errorCallback, Map filter) |
| Contact | Object getProperty(DOMString propertyName) StringArray getSupportedPropertyKeys() void setProperty(DOMString propertyName, Object propertyValue) |
The Contact API provides access to contacts on the device by exposing an array of addressbooks. An AddressBook can be accessed using the getAddressBooks method. An Addressbook is a collection of contacts. Conceptually there are two types of AddressBook, the SIM and device memory addressbook. A contact is a person stored in the Addressbook with properties such a name, phone, address, mail. Contacts in a SIM AddressBook can only store name and phone properties. It is possible to read, create, delete, update contacts in a given AddressBook. The properties supported are returned by the contact class method getSupportedPropertyKeys. These supported keys are valid for the createContact and/or updateContact method. It is also possible to find contacts using a filter supplied to the method findContacts.
bondi.requestFeature(successCB, errorCB, "pim.contact");
// Here we're obtaining the sim addressbook stored at position 1 of the array
var addressbooks = bondi.pim.contact.getAddressBooks();
var sim = addressbooks[1];
This is the list of URIs used to declare this API's features, for use in bondi.requestFeature. For each URL, the list of functions provided is provided.
Device capabilities: pim.contact.read
Device capabilities: pim.contact.write
pim.contact.read
Read the contacts stored in the terminal
pim.contact.write
Writes contacts to be stored in the terminal
AddressBookArray
Array of AddressBook.
typedef sequence<AddressBook> AddressBookArray;
ContactsArray
Array of Contacts.
typedef sequence<Contact> ContactsArray;
ContactArraySuccessCallback
Success callback for retrieving a list of contacts.
[Callback=FunctionOnly, NoInterfaceObject] interface ContactArraySuccessCallback {
void onSuccess(in ContactsArray contacts);
};
Success callback that takes an array of Contacts as input argument. It is used in the asynchronous operation to get a list of contacts.
onSuccess
Method invoked when a list of contacts is retrieved succesfully
void onSuccess(ContactsArray contacts);
ContactManager
The ContactManager interface offers methods to retrieve addressbooks.
interface ContactManager {
AddressBookArray getAddressBooks()
raises(SecurityError);
};
Addressbook availabe are: SIM Device memory AddressBook
getAddressBooks
Returns the available address books in the device.
AddressBookArray getAddressBooks();
var addressbooks = bondi.pim.contact.getAddressBooks();
var simBook = addressbooks[1];
AddressBook
Abstraction of a list of contacts
A list representing all the contacts available in a given addressBook
The AddressBook interface offers methods to
- Find contacts using filters with the findContacs method
- Add contacts using the addContact method
- Update existing contacts using the updateContact method
- Delete a specific contact using the deleteContact method
- Clear the entire contacts list using the clearContact method
interface AddressBook {
Contact createContact([Optional] in Map options)
raises(SecurityError, DeviceAPIError);
PendingOperation addContact(in SuccessCallback successCallback,
in ErrorCallback errorCallback,
in Contact contact)
raises(SecurityError, DeviceAPIError);
PendingOperation updateContact(in SuccessCallback successCallback,
in ErrorCallback errorCallback,
in Contact contact)
raises(SecurityError, DeviceAPIError);
PendingOperation deleteContact(in SuccessCallback successCallback,
in ErrorCallback errorCallback,
in Contact contact)
raises(SecurityError, DeviceAPIError);
PendingOperation deleteAllContacts(in SuccessCallback successCallback,
in ErrorCallback errorCallback)
raises(SecurityError, DeviceAPIError);
PendingOperation findContacts(in ContactArraySuccessCallback successCallback,
in ErrorCallback errorCallback,
in Map filter)
raises(SecurityError, DeviceAPIError);
};
createContact
Creates a contact Object.
Contact createContact(Map options);
The address key is a map with next keys at least supported street, number,postalcode,city,country
var addressbooks = bondi.pim.contact.getAddressBooks();
// Create a map of the contact address property values.
var contactAddress = {street:"Gran Via",number:"32",postalcode:"50013",city:"Zaragoza",country:"Spain"};
// Create a contact.
var contact = addressbooks[0].createContact(
{ name:'Pedro Fraca',
nickName:'peter',
address:contactAddress,
mail:'pedro@gmail.com',
telephone:'6666666666',
photo:'images/pedro.jpg'});
addContact
Adds a contact to the address book.
PendingOperation addContact(SuccessCallback successCallback, ErrorCallback errorCallback, Contact contact);
This is an asynchronous method.
var addressbooks = bondi.pim.contact.getAddressBooks();
// Create a map of the contact address property values.
var contactAddress = {street:"Gran Via",number:"32",postalcode:"50013",city:"Zaragoza",country:"Spain"};
// Create the contact.
var contact = addressbooks[0].createContact(
{ name:'Pedro Fraca',
nickName:'peter',
address:contactAddress,
mail:'pedro@gmail.com',
telephone:'6666666666'});
// Define the success callback.
function successCallback(response) {
alert("Added");
}
// Define the error callback.
function errorCallback(response) {
alert( "The following error: " + response.code + ", occurred adding a contact");
}
// Add it to the address book.
myAddressBooks[0].addContact(successCallback,errorCallback,contact);
updateContact
Updates a contact in the address book.
PendingOperation updateContact(SuccessCallback successCallback, ErrorCallback errorCallback, Contact contact);
This is an asynchronous method.
var addressbooks = bondi.pim.contact.getAddressBooks();
// Retrieve the contact you want to work with using a helper function.
contact = getContactHelper();
// Set a new telephone number for the contact
contact.telephone = "+34666666668";
// Define the success callback.
function successCallback(response) {
alert("Updated");
}
// Define the error callback.
function errorCallback(response) {
alert( "The following error: " + response.code + ", ocurred updating a contact");
}
// Update the contact.
addressbooks[0].updateContact(successCallback,errorCallback,contact);
deleteContact
Deletes a contact from the address book.
PendingOperation deleteContact(SuccessCallback successCallback, ErrorCallback errorCallback, Contact contact);
This is an asynchronous method.
var myAddressBooks = bondi.pim.contact.getAddressBooks();
// Retrieve the contact you want to delete using a helper function.
contact = getContactHelper();
// Define the success callback.
function successCallback(response) {
alert("Deleted");
}
// Define the error callback.
function errorCallback(response) {
alert( "The following error: " + response.code + " ocurred deleting a contact.");
}
myAddressBooks[0].deleteContact(successCallback,errorCallback,contact);
deleteAllContacts
Deletes all contacts in the address book.
PendingOperation deleteAllContacts(SuccessCallback successCallback, ErrorCallback errorCallback);
This is an asynchronous method.
var myAddressBooks = bondi.pim.contact.getAddressBooks();
// Define the success callback.
function successCallback(response) {
alert("Deleted!");
}
// Define the error callback.
function errorCallback(response) {
alert( "The following error: " + response.code + ", occurred deleting all contacts.");
}
// Delete all contacts...
myAddressBooks[0].deleteAllContacts(successCallback, errorCallback);
findContacts
Retrieves an array of Contact Objects for contacts stored within the address book and matching the selected filter.
PendingOperation findContacts(ContactArraySuccessCallback successCallback, ErrorCallback errorCallback, Map filter);
This is an asynchronous method.
In a search using this method, if more than one value is used, then the AND operator will be used betwwen all values to perform the search.
In a search using strings, the search conductes is case sensitive. If the string is found anywhere inside the key object value, the entire object will be returned.
var myAddressBooks = bondi.pim.contact.getAddressBooks();
// Define the success callback.
function successCallback(response) {
alert(response.length + " results found.");
}
// Define the error callback.
function errorCallback(response) {
alert( "The following error: " + response.code + ", occurred finding contacts");
}
// Find all contacts in the first address book with the name 'Guillermo'.
myAddressBooks[0].findContacts(successCallback, errorCallback, {name:"Guillermo"});
Contact
Contact object Abstraction of a device contact. This interface offers properties to manage each contact property It includes methods to get a specific property and to get the available properties to use in the findContact filter, addeContact and updateContact methods. If the contact is a SIM contact only phone and name will be filled. Also if the contact is a SIM contact only phone and name will be returned by the getSupportedPropertyKeys
interface Contact {
attribute DOMString id;
attribute DOMString name;
attribute DOMString nickname;
attribute Map address;
attribute File photo;
attribute DOMString telephone;
attribute DOMString email;
Object getProperty(in DOMString propertyName)
raises(DeviceAPIError);
StringArray getSupportedPropertyKeys();
void setProperty(in DOMString propertyName, in Object propertyValue)
raises(DeviceAPIError);
};
DOMString
id
Unique identifier assigned to the contact in the platform. Read only.
var contact = addressBook.CreateContact();
var id = contact.id;
DOMString
name
Name of the contact.
var contact = addressBook.CreateContact();
contact.name = "Guillermo";
DOMString
nickname
Nickname of the contact.
var contact = addressBook.CreateContact();
contact.nickName = "gcaudev";
Map
address
The address key is a map with the following keys supported street,number,postalcode,city,country
var contact = addressBook.CreateContact();
var contactAddress = {street:"Gran Via",number:"32",postalcode:"50013",city:"Zaragoza",country:"Spain"};
contact.address = contactAddress;
File
photo
Picture of the contact.
var contact = addressBook.CreateContact(null);
contact.photo = "\guillermo.jpg";
DOMString
telephone
Telephone of the contact.
var contact = addressBook.CreateContact(null);
contact.telephone = "+34666666666";
DOMString
email
Email of the contact.
var contact = addressBook.CreateContact(null);
contact.email = "guillermo.caudevilla@vodafone.com";
getProperty
Gets the value of any of the Contact Object properties.
Object getProperty(DOMString propertyName);
This method provides a means of accessing any platform-specific properties that are not already exposed by the standard property attributes.
var location = contact.getProperty("location");
getSupportedPropertyKeys
Returns the supported attributes for contacts in this address book.
StringArray getSupportedPropertyKeys();
var addressbooks = bondi.pim.contact.getAddressBooks();
var attributes = addressbooks[0].getSupportedPropertyKeys();
alert("Number of attributes: " + attributes.length());
setProperty
Sets the value of a Contact Object property.
void setProperty(DOMString propertyName, Object propertyValue);
var name = "Guillermo Caudevilla Laliena";
contact.setProperty("name", name.substring(0, maxSize-1));