Question

I have developed an app in J2me, using on Nokia X2 and c2-05. I do access contacts from the database and write down in the memory, it was working fine until I used phone memory to write contacts, but Now I want to write contacts only to the SIM memory but it doesn't. Although I can read from both SIM and Phone memory but can Only write to phone, while SIM doesn't allow me, its strange. I mean either it should allow to read-write or it shouldn't at all but it allows to read but not writing. Thanks

this is the code I am using

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();
    }
}
Was it helpful?

Solution

Its not possible to write contact on sim. Because sim is provided by the operator, so it may have compatibility issue when you write. Thats why j2me not allowed to write contacts on sim.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top