You can see the content of this post on my site as well, at:
http://www.babyyogurt-piace.it/mambo/content/view/30/2/


I suggest you to read only if you know the JSR-75

The methods below are used to insert or update a contact( only its Contact.FORMATTED_NAME, Contact.TEL - PIMItem.ATTR_NONE) depending on if its UID is already in the contact database. Essentially the whole program is supposed to get a list of the contacts from an external source and insert them in. The program has really strange behaviours. In the phone itself it does the UID check (so from the "uidS" vector it checks if the uid is in already) and then writes only the tel attibute without inserting the UID, and formatted name.This result in a contact having only the mobile number being specified.

In the emulator it inserts all attributes but does not perform the checking on the UID properly. This means that everytime i import the contacts duplicates are inserted.

The code here:

//stard methods to write contacts
public void writeRequest(String id, String name, String tel){
// String temporar = null;
try {
writeContact( id , name , tel ) ;
}
catch (PIMException e)
{
System.err.println ("Msg PIMException From contacts: " + e.toString ());
e.printStackTrace();
}
catch (SecurityException e)
{
System.err.println ("Msg SecurityException From contacts: " + e.toString ());
e.printStackTrace();
}
//return temporar;
}

private void writeContact(String idString , String nameString, String telString)
throws PIMException, SecurityException
{
ContactList contactList = null;
//StringBuffer sb = new StringBuffer();
try
{
contactList = (ContactList) PIM.getInstance()
.openPIMList(PIM.CONTACT_LIST, PIM.WRITE_ONLY);


// First check that the fields we are interested in are supported
// by the PIM List
if (contactList.isSupportedField(Contact.FORMATTED_NAME)
&& contactList.isSupportedField(Contact.TEL))
{
if(uidS.contains(idString )) {//update

//Add contact values
Contact c = contactList.createContact();
int attrs = Contact.ATTR_MOBILE;
c.setString(Contact.TEL, 0, attrs, telString);
// Some fields can be added without attributes
c.setString(Contact.FORMATTED_NAME, 0, PIMItem.ATTR_NONE, nameString);
if (contactList.isSupportedField(Contact.NAME_GIVEN)){
c.setString(Contact.NAME_GIVEN, 0, PIMItem.ATTR_NONE, nameString.substring(0,49));
}
// Add the item to the native contact database
c.commit();

}
else{//insert
//code ti insert
//Add contact values
Contact c = contactList.createContact();
int attrs = Contact.ATTR_MOBILE;
//
c.addString(Contact.UID, PIMItem.ATTR_NONE, idString);
c.addString(Contact.TEL, attrs, telString);
// Some fields can be added without attributes
c.addString(Contact.FORMATTED_NAME, PIMItem.ATTR_NONE, nameString);
if (contactList.isSupportedField(Contact.NAME_GIVEN)){
c.addString(Contact.NAME_GIVEN, PIMItem.ATTR_NONE, nameString.substring(0,49));
}
// Add the item to the native contact database
c.commit();
uidS = new Vector ();

}
}
}
finally
{
// always close it
if (contactList != null)
{
contactList.close();
}
}//End finally
}//End Write Contact