|
Reading/Modifying Native database of mobile device |
|
|
PIM api is an optional J2ME package that gives supports for accessing and
modifying the PIM database that may exist in MIDP device. Three main database
of PIM are Contact list, Event list and To-Do list.
Illustration below create an Event.
EventList events = null;
try {
events = (EventList) PIM.getInstance().openPIMList(PIM.EVENT_LIST,
PIM.READ_WRITE);
}
catch (SecurityException e) {}
catch (PIMException e) {}
Event event = events.createEvent();
try {
if (events.isSupportedField(Event.LOCATION))
event.addString(Event.LOCATION, PIMItem.ATTR_NONE, "Office");
if (events.isSupportedField(Event.SUMMARY))
event.addString(Event.SUMMARY, PIMItem.ATTR_NONE,
"Please call Mr.John");
if (events.isSupportedField(Event.START))
event.addDate(Event.START, PIMItem.ATTR_NONE,
(new Date()).getTime() + 60000);
if (events.isSupportedField(Event.END))
event.addDate(Event.END, PIMItem.ATTR_NONE,
(new Date()).getTime() + 60000 * 5));
if (events.isSupportedField(Event.ALARM))
event.addInt(Event.ALARM, PIMItem.ATTR_NONE,
(new Date()).getTime() + 60000 * 1));
if (events.isSupportedField(Event.NOTE))
event.addString(Event.NOTE, PIMItem.ATTR_NONE,
"Please call Mr.John");
if (events.maxCategories() != 0 && events.isCategory("Reminder"))
event.addToCategory("Reminder");
} catch (PIMException e) {
}
try {
event.commit();
}
catch (SecurityException e) {}
catch (PIMException e) {}
try {
events.close();
} catch (PIMException e) {}
|
Illustration below imports Contact from vcard.
void importContact(InputStream is) {
QuotedPrintableInputStream qpis = new QuotedPrintableInputStream(is);
try {
PIMItem[] items = PIM.getInstance().fromSerialFormat(qpis, "UTF-8");
Contact c = (Contact) (items[0]);
ContactList cl = (ContactList) PIM.getInstance().openPIMList(
PIM.CONTACT_LIST, PIM.READ_WRITE);
cl.importContact(c);
} catch(PIMException pe) {
} catch(IOException ioe) {
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.