menu

秋梦无痕

一场秋雨无梦痕,春夜清风冻煞人。冬来冷水寒似铁,夏至京北蟑满城。

Avatar

Personal Information Management(PIM)

PIM是JSR 75, PDA Optional Packages for the J2ME Platform的一部分,是对MIDP的扩展同时需要设备的支持,并不是通用的。

PIM API包在javax.microedition.pim中,用于访问和修改的PIM数据库,目前支持名片夹(Contact)列表、事件(Event)列表、任务(To-Do)列表。

包括8个接口和6个类:
PIMItem 数据项的上层接口。
PIMList 数据列表的上层接口。
Contact 联系人项的接口。
ContactList 联系人列表接口。
Event 日志项的接口。
EventList 日志列表接口。
ToDo 待办事宜项接口。
ToDoList 待办事宜列表接口。

PIM 提供一系列获得列表的静态方法的类。
RepeatRule 日志项的重复方式。
PIMException PIM类抛出的异常,为下面三个异常的基类。
FieldEmptyException 访问的数据项中的某项数据为空时抛出的异常。
FieldFullException 访问的数据项中的数据条目已满时抛出的异常。
UnsupportedException 访问的数据项中的数据不被支持时抛出的异常。

检查PIM是否可用:

if(System.getProperty( "microedition.pim.version" ) != null){
// PIMOP available
} else {
// PIMOP not available
}

得到ContactList:

PIM pim = PIM.getInstance();
//ContactList,EventList,ToDoList
ContactList list = null;
try {
//PIM.CONTACT_LIST,PIM.EVENT_LIST,PIM.TODO_LIST
//PIM.READ_ONLY,PIM.WRITE_ONLY,PIM.READ_WRITE
list = (ContactList)pim.openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
// do something with the contact list
}catch(PIMException pe){
// no contact list available!
}catch(SecurityException se){
// the application is not allowed to access the list
}

访问list中的数据:

try {
Enumeration items = list.items();
while(items.hasMoreElements()) {
Contact contact = (Contact)items.nextElement();
// do something with the contact
}
}catch(PIMException pe) {
// an error occurred
}catch(SecurityException se) {
// can't read this list
}

得到contact中的数据:

int phoneNumbers = concact.countValues(Contact.TEL);
for(int i = 0; i < phoneNumbers; i++) {
if((contact.getAttributes(Contact.TEL) != 0) & Contact.ATTR_HOME != 0) {
// Home number
String homePhone = contact.getString(Contact.TEL, i);
}
}
long birthday = (contact.getAttributes(Contact.BIRTHDAY) != 0)?contact.getDate(Contact.BIRTHDAY, 0):0;

已经开始了啊
FT~

评论已关闭