我必须基于从通讯录中获取数据来开发解决方案。这些数据必须保存为文本格式。我使用 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 结构。我需要一些工作样本。谁有它?(: