Task
Export a contact.
Import a contact.
Delete a contact.
Close a contacts list.
See "Code sample: Displaying a screen that lets BlackBerry device users add new contacts" on page 45 for more
information.
Steps
1. To import or export PIM item 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()
(PIM.Contact_LIST)
.
3. To write an item to a supported serial format, invoke
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]);
}
1. To return an array of PIM items, invoke
2. To create a new contact using the PIM item, invoke
ontactList.importContact();
C
3. To specify the character encoding to use when writing to the output stream, use the enc
parameter.
// Import contact from vCard.
ByteArrayInputStream istream = new
ByteArrayInputStream(outputStream.toByteArray());
PIMItem[] pi = PIM.getInstance().fromSerialFormat(istream,
"UTF8");
ContactList contactList =
(ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,
PIM.READ_WRITE);
Contact contact2 = contactList.importContact((Contact)pi[0]);
contact2.commit();
removeContact()
>
Invoke
contactList.removeContact(contact);
close()
>
Invoke
.
try {
contactList.close();
} catch(PIMException e) {
Dialog.alert(e.toString());
}
4: Using the address book
and specify the list type
toSerialFormat()
fromSerialFormat()
on a contact list.
. The enc
.
37