Pages

Sunday, April 4, 2010

Using the PIM and FileConnection of Sun Java Wireless Toolkit for CLDC

The Sun JavaTM Wireless Toolkit for CLDC supports JSR 75, the PDA Optional Packages (PDAP) for the J2ME Platform. JSR 75 includes two independent APIs:
  • The FileConnection optional package allows MIDlets access to a local device file system.
  • The Personal Information Management (PIM) optional package includes APIs for manipulating contact lists (address book), calendars, and to-do lists.

This chapter describes how the Sun JavaTM Wireless Toolkit for CLDC implements the FileConnection and PIM APIs.


FileConnection API:

On a real device, the FileConnection API typically provides access to files stored in the device's memory or on a memory card.

In the Sun JavaTM Wireless Toolkit for CLDC emulator, the FileConnection API enables MIDlets to access files stored on your desktop computer's hard disk.

The files that can be accessed using FileConnection are stored in subdirectories of workdir\appdb\skin\filesystem. For example, the DefaultColorPhone emulator skin comes with a root directory installed called root1, which contains a file called Readme and an empty directory named photos. The full path of the file is:

Windows:

workdir\appdb\skin\filesystem\root1\photos

Linux:

workdir/appdb/skin/filesystem/root1/photos


(example: in my PC, the dir workdir i installed is C:\Documents and Settings\user\j2mewtk\2.5.2, and skin maybe DefaultColorPhone)

Note - If multiple instances of the same emulator skin run simultaneously, the Sun JavaTM Wireless Toolkit for CLDC generates unique file paths for each one. For instance, the first directory is named DefaultColorPhone and the second instance is named DefaultColorPhone1.

Each subdirectory of filesystem is called a root. The Sun JavaTM Wireless Toolkit for CLDC provides a mechanism for managing roots. While the emulator is running, choose MIDlet > External events from the emulator window's menu. A utility window for adding and removing roots appears.

Managing File System Roots:

The mounted roots and their contents are available to applications using the FileConnection API.

To add a new root directory, click Mount New and fill in a name for the directory. To make a directory inaccessible to the FileConnection API, select it in the list and click Unmount.

The PIM API:

The Sun JavaTM Wireless Toolkit for CLDC emulator stores contact, calendar, and to-do information in standard files on your desktop computer's hard disk. All information is stored in workdir\appdb\skin\pim. This directory is shared by all running emulators. Lists are stored in subdirectories of the contacts, events, and todo directories. For example, a contact list called Contacts is contained in:

Windows:

workdir\appdb\skin\pim\contacts\Contacts

Linux:

workdir/appdb/skin/pim/contacts/Contacts


Inside the list directory, items are stored in vCard (.vcs) or vCalendar (.vcf) format (see http://www.imc.org/pdi/). Contacts are stored in vCard format, while calendar and to-do items are both stored in vCalendar format.
Source: java.sun.com

1 comment: