Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of PIM in the J2ME optional package

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

The purpose of this article is to share with you about the usage of PIM in the optional package of J2ME. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

If you know anything about the concept of J2ME optional package-PIM, PIM OP defines a series of API and provides ways and means to access these important data. It is necessary to first talk about what OP,OP means optionalpackage (optional package), which does not provide a complete operating environment such as MIDP.

J2ME optional package-introduction to PIM

PIM means personal infomation management (personal Information Management), which is mainly aimed at the user's important information, such as address book, reminder, schedule, etc. PIM OP defines a series of API and provides methods and ways to access these important data. It is necessary to first talk about what OP,OP means optionalpackage (optional package), which does not provide a complete operating environment such as MIDP. It is an extension to MIDP and requires device support. Therefore, it is not general-purpose, and there are problems in portability.

Before using PIM OP, we must determine whether it is available. The simple method is to check whether the property value of microedition.pim.version is null, for example:

. / / CheckthatPIM OPtionalPackageisavailable Stringv=System.getProperty ("microedition.pim.version"); if (vested null) {/ / PIM OPavailable} else {/ / PIM OPnotavailable}.

You cannot determine this 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, namely Contactlist,Eventlist,ToDolist, and the device does not have to support all three types, but he must support at least one.

All the API are in the javax.microedition.pim package. You need 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:

... PIMPIMsingleton=PIM.getInstance (); ContactListcl=null; try {cl= (ContactList) singleton.openPIMList (PIM.CONTACT_LIST, PIM.READ_ONLY); / / usethecontactlist} catch (PIMException) {/ / nocontactlistavailable!} catch (SecurityException) {/ / theapplicationisnotallowedtoaccessthelist}.

SecurityException is worth mentioning, and only trusted MIDlets can access this data for security purposes. If not, this exception is thrown, which is exactly in line with the security mode in MIDP. The data in PIMlist is called PIM item. You can think of PIMlist as a container and PIM item as an entity. To access these item, 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 fields available in PIM item are related to the device implementation, so it is necessary to call its isSupportedField when using a field. The basic data types in the field are also defined in the PIM specification. For example, the TEL field in Contact is String. You get it through the getStri () method, and the birthday field is of long type, for example, through getDate ():

... Contactcontact=...; Stringtel=contact.getString (Contact.TEL,0);. Contactcontact=...; longbday=contact.getDate (Contact.BIRTHDAY,0);...

Multiple fields are included in the contact, and you can access them through the following index.

The above is the use of PIM in the optional package of J2ME. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report