How to list extended fields of ContactList
Article Metadata
Overview
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]);
}
}
contact.commit();
list.close();
} 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.


25 Sep
2009
This article demonstrates the use of the Personal Information Management (PIM) API (JSR-75) in Java ME. It addresses an aspect of the API which is not very well documented, namely the use of so-called extended fields for Contact items. The article shows how to add a Contact item to the ContactList on the phone which makes use of all the extended fields which are available. Aside from all the standard fields which are listed as static fields in the Contact class, some devices also support a whole range of other fields. This functionality would therefore be useful for developers working with the Contact database on devices where these extended fields are supported.
The code example is fairly simple and therefore largely self-explanatory. The two "tricks" in the code are explained at the end of the article, demonstrating how to identify an extended field, and how to identify the anniversary field, which expects a date data type.