Do you know about the concept of the Optional package-PIM in j2s-pa-ha-ha-ha-ha-ha-sha1? Here, I will share with you that the 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 optionalpackage (Optional package), and it does not provide a complete running environment such as MIDP.
Introduction to PIM
PIM refers to personal infomation management personal information management. It 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 optionalpackage (Optional package), and 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:
- ...
- //CheckthatPIM OPtionalPackageisavailable
- Stringv=System.getProperty("microedition.pim.version");
- if(v!=null){
- //PIM OPavailable
- }else{
- //PIM OPnotavailable
- }
- ...
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: Contactlist, Eventlist, and ToDolist. The device must support all these three types, but at least one of them must be supported.
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:
- ...
- PIMPIMsingleton=PIM.getInstance();
- ContactListcl=null;
- try{
- cl=(ContactList)singleton.openPIMList(PIM.CONTACT_LIST,
- PIM.READ_ONLY);
- //usethecontactlist
- }
- catch(PIMException){
- //nocontactlistavailable!
- }
- catch(SecurityException){
- //theapplicationisnotallowedtoaccessthelist
- }
- ...
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. Data in PIMlist is called PIM item. You can regard PIMlist as a container and PIM item as an object. To access these items, you can use the following code:
- importjava.microedition.pim.*;
- importjava.util.*;
- ContactListlist=...//acontactlist
- try{
- Enumerationenum=list.items();
- while(enum.hasMoreElements()){
- Contactcontact=(Contact)enum.nextElement();
- //dosomethingwiththecontact
- }
- }
- catch(PIMExceptione){
- //anerroroccurred
- }
- catch(SecurityExceptione){
- //can'treadthislist
- }
- ...
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:
- ...
- Contactcontact=...;
- Stringtel=contact.getString(Contact.TEL,0);
- ...
- ...
- Contactcontact=...;
- longbday=contact.getDate(Contact.BIRTHDAY,0);
- ...
There are multiple fields in the contact, and you can access them through the index.