我在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();
}
}
答案 0 :(得分:0)
无法在sim上写联系人。因为sim是由运营商提供的,所以在您编写时可能会出现兼容性问题。这就是为什么j2me不允许在sim上写联系人。