A few days ago, I heard from my friends that I was talking about PIM on mobile. This is a cutting-edge technology. I suddenly remembered that I used to see an article on Sun's website about Pim, so I will give a rough introduction to it today.
Pim refers to personal Infomation Management (personal information management), which is mainly used for important user information, such as communication records, reminders, and schedules. Pim op defines a series of APIs and provides methods and channels to access these important data. It is necessary to first talk about What op is. Op means Optional package (Optional package). It does not provide a complete running environment, such as MIDP. The extension of MIDP requires device support. Therefore, it is not common and has problems in portability.
Before using PIM op, we must determine whether it is available. The method is very simple, just to check whether the attribute value of microedition. Pim. version is null, for example:
...
// Check that Pim Optional package is available
String v = system. getproperty ("microedition. Pim. Version ");
If (V! = NULL ){
// Pimop available
} Else {
// Pimop not available
}
...
You cannot identify the above problem by checking whether the PIM package is available in the code, Because PIM is related to the device implementation. Pim defines three types of information: contact list, event list, And todo list. devices must support all these three types, but they must support at least one.
All APIs are stored in javax. microedition. in the PIM package, you need to use Pim. you can call the openpimlist () method to obtain the PIM class. 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
}
Catch (pimexception ){
// No contact list available!
}
Catch (securityexception ){
// The application is not allowed to access the list
}
...
It is worth mentioning that securityexception, in order to ensure security, only trusted midlets can access the data. If not, this exception will be thrown, which is in line with the security mode in MIDP. The data in the PIM list is called the PIM item. You can regard the PIM list as a container and the PIM item as an object. To access these items, you can use the following code:
Import java. microedition. Pim .*;
Import java. util .*;
Contactlist list =... // a contact list
Try {
Enumeration Enum = List. Items ();
While (enum. hasmoreelements ()){
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 available fields in PIM item are related to the device implementation. Therefore, when using a field, it is necessary to call its issupportedfield to judge, the basic data type in the field is also defined in the PIM specification. For example, the Tel field in the contact is string, which you can get through the getstri () method, the birthday field is of the long type and is obtained through getdate (), for example:
...
Contact contact = ...;
String Tel = contact. getstring (contact. Tel, 0 );
...
...
Contact contact = ...;
Long bday = contact. getdate (contact. Birthday, 0 );
...
There are multiple fields in the contact, and you can access them through the index.
Let's just talk about it. I hope it will be useful to everyone!