I listened to my friends a few days ago, I was talking about PIM issues, which is a comparative frontier technology. I suddenly remembered that I have seen an article in the Sun's website, so I introduced it today.
PIM means Personal Infomation Management (personal information management), mainly for users, such as communication records, reminders, schedules, etc. PIM OP defines a series of APIs that provide methods and ways to access these important data. It is necessary to talk about what is OP, OP means Optional Package, which does not provide a complete set of runtime, such as MIDP. He is an extension of MIDP while needing to support. Therefore, he is not universal, there is a problem in portability.
Before using PIM OP, we must judge whether it is available, the method is simple to check the property value of Microedition.Pim.Version is NULL, for example: ... // check what Pim Optional package is availableString v = system.getProperty (" MicroEDition.pim.version "); if (v! = null) {// pimop available} else {// pimop not available} ...
You cannot check whether the PIM packet can be used in the code, because PIM is related to the device implementation. PIM defines three types of information, which are Contact List, Event List, Todo List, and equipment and must support all three types, but he should support one at least.
All APIs are in the javax.microedition.pim package, you have to get the PIM class through the Pim.GetInstance () method, and then you can call the openpimlist () method to get the above list. For example, the following code: ... PIM Singleton = pim.getinstance (); ContactList CL = NULL;
try {cl = (ContactList) singleton.openPIMList (PIM.CONTACT_LIST, PIM.READ_ONLY); // use the contact list} {! // no contact list available} catch (PIMException) catch (SecurityException) {// the application is NOT ALLOWED to Access the List} ...
It is worth mentioning that SecurityException, which can access these data for security only trusted MIDlets. If not, this exception will be thrown, which is just in line with the security mode in MIDP. The data in the PIM List is called PIM ITEM, you can regard the PIM List as a container, regard the PIM ITEM as an entity. To access these Items can pass the following code: import java.microedition.pim. *; Import java.util. *;
ContactList List = ... // a Contact List
Try {enumeration enum = list.items (); while (enum.hasmorelements ()) {Contact Contact = (Contact) enum.nextelement (); // do something with the contact} catch (pimexception e) {// AN ERROR OCCURRED} catch (securityException e) {// can't read this list} ... The field with the field available in PIM ITEM is related, so it is necessary to call it if Issupportedfield when using a field. Judgment, the PIM specification also defines the basic data type in the field. For example, the TEL field inside Contact is String you to get through the getStri () method, the birthday field is the long-type () through getdate (), for example: ... Contact Contact = ...; String Tel = Contact.getstring (Contact.tel, 0); ...
... Contact Contact = ...; long bday = contact.getdate (contact.birdhday, 0); ...
In Contact, multiple fields, you can access them through the following INDEX.
Just say so much, I hope to use it!