J2-optional package-detailed description of PIM usage

Source: Internet
Author: User

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:

 
 
  1. ...  
  2. //CheckthatPIM OPtionalPackageisavailable  
  3. Stringv=System.getProperty("microedition.pim.version");  
  4. if(v!=null){  
  5. //PIM OPavailable  
  6. }else{  
  7. //PIM OPnotavailable  
  8. }  
  9. ... 

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:

 
 
  1.  ...  
  2. PIMPIMsingleton=PIM.getInstance();  
  3. ContactListcl=null;  
  4. try{  
  5. cl=(ContactList)singleton.openPIMList(PIM.CONTACT_LIST,  
  6. PIM.READ_ONLY);  
  7. //usethecontactlist  
  8. }  
  9. catch(PIMException){  
  10. //nocontactlistavailable!  
  11. }  
  12. catch(SecurityException){  
  13. //theapplicationisnotallowedtoaccessthelist  
  14. }  
  15. ...  

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:

 
 
  1. importjava.microedition.pim.*;  
  2. importjava.util.*;  
  3. ContactListlist=...//acontactlist  
  4. try{  
  5. Enumerationenum=list.items();  
  6. while(enum.hasMoreElements()){  
  7. Contactcontact=(Contact)enum.nextElement();  
  8. //dosomethingwiththecontact  
  9. }  
  10. }  
  11. catch(PIMExceptione){  
  12. //anerroroccurred  
  13. }  
  14. catch(SecurityExceptione){  
  15. //can'treadthislist  
  16. }  
  17. ...  

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:

 
 
  1. ...  
  2. Contactcontact=...;  
  3. Stringtel=contact.getString(Contact.TEL,0);  
  4. ...  
  5. ...  
  6. Contactcontact=...;  
  7. longbday=contact.getDate(Contact.BIRTHDAY,0);  
  8. ... 

There are multiple fields in the contact, and you can access them through the index.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.