我在 J2me 中开发了一个应用程序,在诺基亚 X2 和 c2-05 上使用。我确实从数据库中访问联系人并在内存中写下来,它工作正常,直到我使用手机内存写入联系人,但现在我只想将联系人写入 SIM 内存,但它没有。虽然我可以从 SIM 和手机内存中读取,但只能写入手机,而 SIM 不允许我,这很奇怪。我的意思是要么它应该允许读写,要么它根本不应该,但它允许读取但不允许写入。谢谢
这是我正在使用的代码
private class ContactWriter {
private ContactList clist;
public ContactWriter() throws PIMException {
clist = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.WRITE_ONLY, "SIM"); //or I used list[1] in my case its SIM, but still didn't get that!
}
public void close() throws PIMException {
clist.close();
}
public void commitContact(ContactDTO contact) throws PIMException {
Contact c = clist.createContact();
String name[] = new String[clist.stringArraySize(Contact.NAME)];
String addr[] = new String[clist.stringArraySize(Contact.ADDR)];
if (contact.getName() != null) {
if (clist.isSupportedField(Contact.NAME)) {
boolean yes = false;
if (clist.isSupportedArrayElement(Contact.NAME, Contact.NAME_GIVEN)) {
name[Contact.NAME_GIVEN] = contact.getName();
yes = true;
} else if (clist.isSupportedArrayElement(Contact.NAME, Contact.NAME_OTHER)) {
name[Contact.NAME_OTHER] = contact.getName();
yes = true;
} else if (clist.isSupportedArrayElement(Contact.NAME, Contact.NAME_FAMILY)) {
name[Contact.NAME_FAMILY] = contact.getName();
yes = true;
}
if (yes) {
c.addStringArray(Contact.NAME, Contact.ATTR_NONE, name);
}
} else if (clist.isSupportedField(Contact.FORMATTED_NAME)) {
c.addString(Contact.FORMATTED_NAME, Contact.ATTR_NONE, contact.getName());
}
}
if (contact.getAddress() != null) {
if (clist.isSupportedField(Contact.ADDR)) {
boolean yes = false;
if (clist.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_EXTRA)) {
addr[Contact.ADDR_EXTRA] = contact.getAddress();
yes = true;
} else if (clist.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_STREET)) {
addr[Contact.ADDR_STREET] = contact.getAddress();
yes = true;
}
if (yes) {
c.addStringArray(Contact.ADDR, Contact.ATTR_NONE, addr);
}
} else if (clist.isSupportedField(Contact.FORMATTED_ADDR)) {
c.addString(Contact.FORMATTED_ADDR, Contact.ATTR_NONE, contact.getAddress());
}
}
if (clist.isSupportedField(Contact.TEL)) {
if ((clist.isSupportedAttribute(Contact.TEL, Contact.ATTR_HOME)) && (contact.getPhoneHome() != null)) {
c.addString(Contact.TEL, Contact.ATTR_HOME, contact.getPhoneHome());
}
if ((clist.isSupportedAttribute(Contact.TEL, Contact.ATTR_MOBILE)) && (contact.getPhoneMobile() != null)) {
c.addString(Contact.TEL, Contact.ATTR_MOBILE, contact.getPhoneMobile());
}
if ((clist.isSupportedAttribute(Contact.TEL, Contact.ATTR_WORK)) && (contact.getPhoneWork() != null)) {
c.addString(Contact.TEL, Contact.ATTR_WORK, contact.getPhoneWork());
}
if ((clist.isSupportedAttribute(Contact.TEL, Contact.ATTR_PAGER)) && (contact.getPager() != null)) {
c.addString(Contact.TEL, Contact.ATTR_PAGER, contact.getPager());
}
}
if ((clist.isSupportedField(Contact.EMAIL)) && (contact.getEmail() != null)) {
c.addString(Contact.EMAIL, Contact.ATTR_NONE, contact.getEmail());
}
if ((clist.isSupportedField(Contact.ORG)) && (contact.getOrganisation() != null)) {
c.addString(Contact.ORG, Contact.ATTR_NONE, contact.getOrganisation());
}
c.commit();
}
}