Revision as of 08:14, 6 February 2012 by hamishwillee (Talk | contribs)

How to list extended fields of ContactList

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: jarmlaht (24 Jan 2008)
Last edited: hamishwillee (06 Feb 2012)


When using PIM API and its ContactList class, it is important to find out first, what fields are supported by the implementation. This can be done by using the instructions shown here: How to list the supported fields in a PIMList.

It is also possible, that implementations have so called extended fields. They are additional fields, which are not listed as standard fields of Contact class. Some of the latest S60 implementations (S60 3rd Ed FP1 and newer) support a wide selection of these fields. Below is a method for creating a contact, which has a name "Test Contact" and all the extended attributes, which are available. This method has been tested in S60 3rd Edition FP1 devices like N95.

public void testExtendedFields() {
ContactList list = null;
Contact contact = null;
try {
list = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
contact = list.createContact();
String[] name = new String[list.stringArraySize(Contact.NAME)];
if (list.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY)) name[Contact.NAME_FAMILY] = "Contact";
if (list.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN)) name[Contact.NAME_GIVEN] = "Test";
contact.addStringArray(Contact.NAME, PIMItem.ATTR_NONE, name);
int fields[] = list.getSupportedFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i] > 256) { // extended field
if (fields[i] == 16797704) { // Anniversary field
contact.addDate(fields[i], Contact.ATTR_NONE, new java.util.Date().getTime());
else contact.addString(fields[i], Contact.ATTR_NONE, "field: " + fields[i]);
} catch (PIMException pe) {
System.out.println("PIMException: " + pe.getMessage());
} catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException: " + iae.getMessage());

Note: The existence of extended fields is tested by checking, if the integer value of a field is more then 256.

Note: The field having value of 16797704 (Anniversary field) accepts only a Date object as its content, others accept Strings.

See also:

52 page views in the last 30 days.