42
BlackBerry Device Applications Integration Guide
Export a task.
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.
2. To retrieve a string array of supported serial formats, invoke
PIM.supportedSerialFormats()
, and then specify the list type (
PIM.TODO_List
).
3. To write an item to a 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.
ToDoList todoList = (ToDoList)PIM.getInstance().openPIMList(
PIM.TODO_LIST, PIM.READ_ONLY);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
String[] dataFormats =
PIM.getInstance().supportedSerialFormats(PIM.TODO_LIST);
Enumeration e = todoList.items();
while (e.hasMoreElements()) {
ToDo task = (ToDo)e.nextElement();
PIM.getInstance().toSerialFormat(task, byteStream, "UTF8",
dataFormats[0]);
}
Import a task.
1.
To return an array of
PIMItem
objects, invoke
fromSerialFormat()
. 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.
2. To create a new task using the PIM items, invoke
ToDoList.importToDo()
. The
importToDo()
method saves the task; you do not have to invoke
commit()
.
String[] dataFormats = PIM.toDoSerialFormats();
// Write task to serial format.
ByteArrayOutputStream os = new ByteArrayOutputStream();
PIM.getInstance().toSerialFormat(task, os, "UTF8", dataFormats[0]);
// Import task from serial format.
ByteArrayInputStream is = new
ByteArrayInputStream(outputStream.toByteArray());
PIMItem[] pi = PIM.getInstance().fromSerialFormat(is, "UTF8");
ToDoList todoList = (ToDoList)PIM.getInstance().openPIMList(
PIM.TODO_LIST, PIM.READ_WRITE);
ToDo task2 = todoList.importToDo((ToDo)pi[0]);
Delete a task.
>
Invoke
removeToDo()
on a task list.
todoList.removeToDo(task);
Close a task list.
1.
Invoke
todoList.close()
.
2. Create code that manages exceptions.
try {
todoList.close();
} catch (PimException e) {
// Handle exception.
}
Task
Steps
Содержание JAVA DEVELOPMENT ENVIRONMENT - - DEVICE APPLICATIONS INTEGRATION - DEVELOPMENT GUIDE
Страница 1: ...BlackBerry Java Development Environment Version 4 6 0 BlackBerry Device Applications Integration Guide...
Страница 4: ......
Страница 7: ......
Страница 10: ...10 BlackBerry Device Applications Integration Guide...
Страница 12: ...12 BlackBerry Device Applications Integration Guide...
Страница 50: ...50 BlackBerry Device Applications Integration Guide...
Страница 56: ...56 BlackBerry Device Applications Integration Guide...
Страница 65: ......
Страница 66: ...2008 Research In Motion Limited Published in Canada...