Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 13:25, 3 June 2009 by jarmlaht (Talk | contribs)

How to list extended fields of ContactList

From Wiki
Jump to: navigation, search


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:

25 page views in the last 30 days.