我必须基于从地址簿中获取数据来开发解决方案。 这些数据必须保存为文本格式。我用Java™Platform Micro Edition SDK 3.0编写了它。
public void getAddrBook() throws Exception{
addrStr= new StringBuffer("");
pim = PIM.getInstance();
try{
contactList = (ContactList)pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
itemList.removeAllElements();
int kk=0;
for (Enumeration items = contactList.items(); items.hasMoreElements();kk++) {
PIMItem item = (PIMItem)items.nextElement();
itemList.addElement(item);
if (kk>5) break;
//detailed enumeration of fields
int[] fields = item.getPIMList().getSupportedFields();
for (int i = 0; i < fields.length; i++) {
int field = fields[i];
int dataType = item.getPIMList().getFieldDataType(field);
String label = item.getPIMList().getFieldLabel(field);
//checking type of PIMItem
//can be STRING, BOOLEAN, STRING_ARRAY, DATE, INT, BINARY
if (dataType==PIMItem.STRING){
for (int j=0; j
}
//String sValue = item.getString(field, 0);
//System.out.println("["+label+"] - "+sValue);
//System.out.println("["+label+"] - ");//+sValue);
}
}
}
}
catch(PIMException e){
throw new Exception("Some errors with access to address book");
//TODO: check empty list and other
}
}
但是此代码仅适用于模拟器,不适用于真实手机。 我应该如何使用PIM以文本格式保存数据?
另外,我允许访问联系簿。我认为错误是使用PIM结构。 我需要一些工作样本。谁拥有它? (:
答案 0 :(得分:2)
JSR75 PIM API具有内置的安全功能,需要应用程序由受信任的来源进行数字签名。签名可以在GeoTrust这样的网站上完成(我已经将它用于索尼爱立信W810的AT&amp; T)。
除了对应用程序进行签名之外,还需要在应用程序的JAD文件中启用权限。 PIM API可以使用以下6个权限。
javax.microedition.pim.ContactList.read
javax.microedition.pim.ContactList.write
javax.microedition.pim.EventList.read
javax.microedition.pim.EventList.write
javax.microedition.pim.ToDoList.read
javax.microedition.pim.ToDoList.write