Delete a contact

You can delete a contact from the default contact list or another contact list on a BlackBerry® device.

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.pdap.BlackBerryContact; 
    import net.rim.blackberry.api.pdap.BlackBerryPIMList;
    import net.rim.device.api.system.ControlledAccessException;
    import javax.microedition.pim.Contact;
    import javax.microedition.pim.ContactList;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;
  2. To delete a contact from the default contact list, invoke PIM.openPIMList(int, int) to open the default contact list instance, passing in as parameters the type of list to open (PIM.CONTACT_LIST), and the access mode with which to open the list (PIM.READ_WRITE, PIM.READ_ONLY, or PIM.WRITE_ONLY). Proceed to step 4.
    BlackBerryContactList contactList = (BlackBerryContactList) 
       PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
  3. To delete a contact from a contact list that is not the default contact list, perform the following actions:
    1. Invoke listPIMLists(int pimListType) to return an array of String objects. The returned array provides the system-assigned name for each contact list. The default contact list is returned at index 0 of the array.
      String[] lists = PIM.listPIMLists(PIM.CONTACT_LIST);
    2. Iterate over the array that PIM.listPIMLists() returns to search for the system-assigned name for the contact list that you want to delete.
    3. Invoke PIM.openPIMList(int, int, String) to open the contact list instance, passing in as parameters the type of list to open (PIM.CONTACT_LIST), the access mode with which to open the list (PIM.READ_WRITE, PIM.READ_ONLY, or PIM.WRITE_ONLY), and the contact list name.
      BlackBerryContactList contactList = (BlackBerryContactList)
         PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE, name);
  4. Invoke BlackBerryContactList.removeContact() to delete the contact from the contact list.
    contactList.removeContact(contact);
  5. Check for PIMException, and check for ControlledAccessException if your application does not have permission to access the application that it invokes.
Previous topic: Import a contact

Was this information helpful? Send us your comments.