我的 j2me 应用程序具有与电话和 sim 中的联系人进行消息传递的功能。我测试了应用程序,并且在诺基亚 N70 M 和诺基亚 C2-02 上也运行良好。但不能从诺基亚 E5 和 E72 获取联系人。请让我知道我错了的错误可能性,在这里给你代码......
public void loadContacts()
{
System.out.println("into show contacts1");
try
{
javax.microedition.pim.ContactList addressbook=null;
javax.microedition.pim.ContactList simaddressbook=null;
PIM pim = PIM.getInstance();
System.out.println("into show contacts2");
String[] allContactLists = PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);
System.out.println("into show contacts3");
for(int ctr=0;ctr<allContactLists.length;ctr++)
{
pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY,allContactLists[ctr]);
addressbook=(javax.microedition.pim.ContactList)(pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY));
Contact contact = null;
Enumeration items = null;
items = addressbook.items();
while (items.hasMoreElements()) {
contact = (Contact) items.nextElement();
int telCount = contact.countValues(Contact.TEL);
int nameCount = contact.countValues(Contact.FORMATTED_NAME);
if (telCount > 0 && nameCount > 0) {
String contactName = contact.getString(Contact.FORMATTED_NAME, 0);
for (int i = 0; i < telCount; i++) {
String phoneNumber = contact.getString(Contact.TEL, i);
ContactFetcher contactfetcher=new ContactFetcher();
contactfetcher.setFotmattedName(contactName);
contactfetcher.settelName(phoneNumber);
PersistableManager pm=PersistableManager.getInstance();
pm.save(contactfetcher);
}
}
}
}
if(!nokiaos)
{
simaddressbook=(javax.microedition.pim.ContactList)(PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE,"SIM"));
Contact contact = null;
Enumeration simitems=null;
simitems=simaddressbook.items();
while (simitems.hasMoreElements()) {
System.out.println("into show contacts9");
contact = (Contact) simitems.nextElement();
int telCount = contact.countValues(Contact.TEL);
int nameCount = contact.countValues(Contact.FORMATTED_NAME);
if (telCount > 0 && nameCount > 0) {
String contactName = contact.getString(Contact.FORMATTED_NAME, 0);
for (int i = 0; i < telCount; i++) {
String phoneNumber = contact.getString(Contact.TEL, i);
ContactFetcher contactfetcher=new ContactFetcher();
contactfetcher.setFotmattedName(contactName);
contactfetcher.settelName(phoneNumber);
PersistableManager pm=PersistableManager.getInstance();
pm.save(contactfetcher);
}
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
在这里,我检测手机是 s60 还是 s40,如果 s6o 则只读取 s60 中的 pim 联系人和 s40 中的 sim 联系人。提前致谢...:)