This page was last modified 09:37, 12 May 2008.
Listing PIM databases using JSR 75
From Forum Nokia Wiki
| ID | Creation date | May 12, 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() |
Overview
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 wonder if the MIDlet asks several times the permission to read user data. This is due to the javax.microedition.pim.PIM.listPIMLists() method call and normal behavior for untrusted MIDlets.
Source file: PIMMIDlet.java
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); } /** * Called when the MIDlet is started. */ public void startApp() { Display.getDisplay(this).setCurrent(pimDatabases); } // Other inherited methods omitted for brevity // ... public void exit() { destroyApp(true); notifyDestroyed(); } }
Source file: PIMDbForm.java
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.exit(); } } /** * 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); } } }
Postconditions
The MIDlet displays on a form all PIM databases that exist on the device.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Thumbnail listing of images | ashokkalarickal | General Symbian C++ | 0 | 2007-09-29 06:26 |
| SVG on Nokia 6680 | nicenouman | Mobile Java General | 2 | 2007-01-16 18:17 |
| PIM problem | jack_lu | Mobile Java General | 1 | 2007-11-22 12:52 |
| 9300, 9500 | ktubail | Mobile Java Tools & SDKs | 2 | 2006-02-08 01:09 |
| MIDP Security | JackAirman | Mobile Java General | 7 | 2006-12-18 17:23 |
