Personal Information Management (PIM) in mobile environments
As new devices continue to come on the market, it is an inevitable requirement to provide address book, Calendar, and Task List on mobile devices. J2ME applications also need access to this data. Optional packet JSR Personal information Management (PIM) provides this functionality.
Not only does it allow access to local personal information that contains contacts, appointments, and tasks, but it also allows access to information based on the SIM card attached to the device and the Personal information database.
The PIM package supports importing and exporting data from vcard and VCalendar, and the vcard and VCalendar are the Internet standard formats for address Book and Calendar respectively. It also has security features that prevent unauthorized classes from retrieving personal information.
Another optional package JSR Connection provides a way to access a local file system outside the scope of this article.
J2ME PIM Package
The Java PIM package is represented by a JAVAX.MICROEDITION.PIM package.
The key interfaces defined by this package include:
contact--This interface represents a single contact on the address Book.
contactlist--this interface represents the address book, which is a list of contacts.
event--This interface represents a single Calendar Event.
eventlist--This interface represents a list of Calendar events.
todo--This interface represents a single task in the task List.
todolist--This interface represents a Task list.
The main classes defined by this package are:
The Pim--pim class defines methods for creating an index of all existing lists, opening and editing those lists as import or export from the VCard and VCalendar (Internet standard for contact and Calendar).
Contact and ContactList
A contact represents a single entry in the Address Book. The main fields in the contact are Name, address, Email, birthday, Photo, and telephone.
To ensure cross-platform portability, it is recommended to use the method provided by the Super Interface pimlist Issupportedfield ().
Listing 1 shows how to add a contact to the Address book:
Listing 1. Add Contact to Address Book
ContactList addressbook = null;
try {
AddressBook = (contactlist) pim.getinstance (). Openpimlist (PIM. Contact_list,
Pim. Read_write);
catch (Pimexception e) {
Exit Application
}
Contact singlecontact = Addressbook.createcontact ();
string[] name = new String[addressbook.stringarraysize (contact.name)];
if (Addressbook.issupportedfield (contact.name_formatted)
Singlecontact.addstring (contact.name_formatted,
Pimitem.attr_none, "Mrs Jane Doe");
The CreateContact () method creates a temporary empty contacts. A commit () call makes
The contact data persistent. It is advisable to close the lists by invoking the close ()
Method after necessary operations have been performed.
try {
Singlecontact.commit ();
catch (Pimexception e) {
Exception occured
}
try {
Other cleanup tasks
Addressbook.close ();
catch (Pimexception e) {
}