123452'm trying to create an application to back up a phone's contacts on a server and read them back into the phone again afterwards.

I'm exporting and importing the contacts in a VCARD 2.1 format using fromSerialFormat and toSerialFormat, which seems to work fine.

The only issue I'm having with this is that, when writing the contacts back to the phone, I don't want it to create a copy of the contact if it already exists. The code I'm using is as follows:

HttpConnection sc = (HttpConnection) Connector.open(url);

InputStream is = sc.openInputStream();

PIMItem[] temp = PIM.getInstance().fromSerialFormat(is, "UTF-8");

PIMItem item = (PIMItem) temp[0];

contact  = ((ContactList)addressbook).importContact((Contact) item);

int[] fields = contact.getFields();

for (int k=0; k<fields.length; k++)
if (fields[k]==contact.REVISION)
       contact.removeValue(contact.REVISION, contact.ATTR_NONE);

Enumeration matching = addressbook.items(contact);
            if(matching.hasMoreElements()) {
              this.append("found the contact");
            } else {
              this.append("adding the contact");
The previous problem I had was with the contact.REVISION field being different, thus flagging the contacts as being different. After stripping out the contact.REVISION field, this code works fine on an emulator. But on the phone that I'm testing it on (a Nokia 6500 slide), it still creates copies of the contacts that are already present in the contacts list.

Any ideas would be appreciated.