Troubleshooting guide
174
BlackBerry Java Development Environment Development Guide
Retrieve contact information. 1. Invoke PIMList.items().
2. Perform one of the following actions:
• To retrieve an array of IDs for fields that have data for a particular contact, invoke
PIMItem.getFields() .
• To retrieve the field values, invoke PIMItem.getString().
3. When you invoke PIMList.items() to retrieve an enumeration of items in a contacts
list, your application must sort items as necessary.
ContactList contactList =
(ContactList)PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_WRITE);
Enumeration enum = contactList.items();
while (enum.hasMoreElements()) {
Contact c = (Contact)enum.nextElement();
int[] fieldIds = c.getFields();
int id;
for(int index = 0; index < fieldIds.length; ++index) {
id = fieldIds[index];
if(c.getPIMList().getFieldDataType(id) == Contact.STRING) {
for(int j=0; j < c.countValues(id); ++j) {
String value = c.getString(id, j);
System.out.println(c.getPIMList().getFieldLabel(id) + "=" +
value);
}
}
}
}
Export a contact. 1. To import or export PIM data, use an output stream writer to export tasks from the
BlackBerry device to a supported serial format, such as vCard®.
2. To retrieve a string array of supported formats, invoke
PIM.supportedSerialFormats() and specify the list type
(PIM.Contact_LIST)
.
3. To write an item to a supported serial format, invoke toSerialFormat(). The enc
parameter specifies the character encoding to use when writing to the output stream.
Supported character encodings include "UTF8," "ISO-8859-1," and "UTF-16BE." This
parameter cannot be null.
ContactList contactList =
(ContactList)PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_ONLY);
String[] dataFormats = PIM.getInstance().supportedSerialFormats(
PIM.CONTACT_LIST);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
Enumeration e = contactList.items();
while (e.hasMoreElements()) {
Contact c = (Contact)e.nextElement();
PIM.getInstance().toSerialFormat(c, byteStream, "UTF8",
dataFormats[0]);
}
Task Steps