| ID | CS000972 | Creation date | May 20, 2008 |
| Platform | S60 3rd Edition, MR | Tested on devices | Nokia E61i |
| Category | Java ME | Subcategory | File Connection and PIM API (JSR-75) |
| Keywords (APIs, classes, methods, functions): javax.microedition.pim.PIM, javax.microedition.pim.PIM.getInstance(), javax.microedition.pim.PIM.listPIMLists() |
The Personal Information Manager (PIM) API for Java ME (JSR-75) allows mobile Java applications to read/write to/from the locally stored personal information databases. There are three categories of PIM databases: contacts, calendar, and to-do. This code snippet demonstrates how to list PIM databases (also called PIM lists) that exist on the device.
Note: Don't be surprised if the MIDlet asks several times for permission to read user data. This is due to the javax.microedition.pim.PIM.listPIMLists() method call and normal behavior for untrusted MIDlets.
import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
public class PIMMIDlet extends MIDlet {
private PIMDbForm pimDatabases;
/**
* Constructor. Constructs the object and initializes displayables.
*/
public PIMMIDlet() {
pimDatabases = new PIMDbForm(this);
}
/**
* From MIDlet.
* Called when the MIDlet is started.
*/
public void startApp() {
Display.getDisplay(this).setCurrent(pimDatabases);
}
/**
* From MIDlet.
* Called to signal the MIDlet to enter the Paused state.
*/
public void pauseApp() {
// No implementation required
}
/**
* From MIDlet.
* Called to signal the MIDlet to terminate.
* @param unconditional whether the MIDlet has to be unconditionally
* terminated
*/
public void destroyApp(boolean unconditional) {
// No implementation required
}
}
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.pim.PIM;
/**
* A list of PIM databases.
*/
public class PIMDbForm extends Form implements CommandListener {
private Command exitCommand;
private PIMMIDlet parent;
private int itemCounter = 0; // How many items are listed
public PIMDbForm(PIMMIDlet parent) {
super("PIM databases");
this.parent = parent;
exitCommand = new Command("Exit", Command.EXIT, 0);
addCommand(exitCommand);
setCommandListener(this);
// Retrieve the PIM instance
PIM pim = PIM.getInstance();
// Add each type of PIM lists (PIM databases) to the form
addList(PIM.CONTACT_LIST, pim);
addList(PIM.EVENT_LIST, pim);
addList(PIM.TODO_LIST, pim);
}
public void commandAction(Command command, Displayable displayable) {
if (command == exitCommand) {
// Exit the MIDlet
parent.notifyDestroyed();
}
}
/**
* Adds the names of specific types of PIM lists (databases) to the form.
* @param listType the type of list
* @param pim PIM instance from which the databases are queried
*/
private void addList(int listType, PIM pim) {
String[] list = pim.listPIMLists(listType);
for (int i = 0; i < list.length; i++) {
itemCounter++;
StringItem item = new StringItem("Database " + itemCounter, list[i]);
append(item);
}
}
}
The MIDlet displays all PIM databases that exist on the device on a form.
No related wiki articles found