J2ME抓取SIM卡联系人
问题描述:
如何在J2ME中使用PIM检索SIM卡和电话簿联系人。我试过 PIM.getInstance()。listPIMLists(PIM.CONTACT_LIST); 但它只显示电话簿联系人。J2ME抓取SIM卡联系人
答
可能是这种方法可以帮助你
public static HashLongObject loadContactFromPhone() {
PIM iPim = PIM.getInstance();
String[] allContactLists = iPim.listPIMLists(PIM.CONTACT_LIST);
// Phone or SIM
HashLongObject iPhoneBookList = new HashLongObject();
int i;
for (i = 0; i < allContactLists.length; i++) {
try {
PIMList iPIMList = iPim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, allContactLists[i]);
Enumeration iPimListEnum = iPIMList.items();
String iContactName, iTelNumber;
String []arrName;
boolean isSupportFormettedName = iPIMList.isSupportedField(Contact.FORMATTED_NAME);
if(isSupportFormettedName) {
while (iPimListEnum.hasMoreElements()) {
try {
Contact iContact = (Contact) iPimListEnum.nextElement();
iContactName = iContact.getString(Contact.FORMATTED_NAME, 0);
iTelNumber = iContact.getString(Contact.TEL, 0);
} catch (Exception e) {
Logger.logStackTrace(e);
continue;
}
long corePhoneNumber = StringUtils.toCCPhoneNumber(iTelNumber);
// Check Duplicate
if (iPhoneBookList.containsKey(corePhoneNumber)) {
continue;
}
iPhoneBookList.put(corePhoneNumber, iContactName);
}
} else {
while (iPimListEnum.hasMoreElements()) {
try {
Contact iContact = (Contact) iPimListEnum.nextElement();
arrName = iContact.getStringArray(Contact.NAME, Contact.ATTR_NONE);
iContactName = "";
if(arrName[Contact.NAME_FAMILY] != null) {
iContactName += arrName[Contact.NAME_FAMILY];
}
if(arrName[Contact.NAME_GIVEN] != null) {
iContactName += arrName[Contact.NAME_GIVEN];
}
iTelNumber = iContact.getString(Contact.TEL, 0);
} catch (Exception e) {
Logger.logStackTrace(e);
continue;
}
long corePhoneNumber = StringUtils.toCCPhoneNumber(iTelNumber);
// Check Duplicate
if (iPhoneBookList.containsKey(corePhoneNumber)) {
continue;
}
iPhoneBookList.put(corePhoneNumber, iContactName);
}
}
} catch (PIMException ex) {
Logger.logStackTrace(ex);
} catch (Exception otherEx) {
Logger.logStackTrace(otherEx);
}
}
return iPhoneBookList;
}
的[你能从J2ME访问SIM卡联系人?](
可能重复http://stackoverflow.com/questions/4955323/can-you-access-sim -contacts-from-j2me) – Nate 2013-02-16 05:19:34
对listPIMLists的调用只返回一个列表? – 2013-02-16 21:04:13
是的,它只返回一个电话簿联系人列表。当我尝试使用simaddressbook =(javax.microedition.pim.ContactList)(PIM.getInstance()。openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE,“SIM”))来读取SIM联系人时;但它给予空指针异常 – jaya 2013-02-18 10:56:17