Open the contacts application with a specific contact list

You can open the contacts application on a BlackBerry® device and display a specific contact list by invoking the BlackBerryContactList.choose() method.

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.pdap.BlackBerryContact;
    import net.rim.blackberry.api.pdap.BlackBerryContactGroup;
    import net.rim.blackberry.api.pdap.BlackBerryContactList;
    import net.rim.blackberry.api.pdap.BlackBerryPIM;
    import net.rim.blackberry.api.pdap.BlackBerryPIMList;
    import net.rim.device.api.system.ControlledAccessException;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;
    import javax.microedition.pim.PIMItem;
  2. Invoke PIM.listPIMLists(int pimListType) to return an array of String objects. The returned array provides the system-assigned names, one for each PIM list of the specified type. The default list of the specified type is returned at index 0 of the array.
    String[] lists = PIM.listPIMLists(PIM.CONTACT_LIST);
  3. Iterate over the array that is returned from PIM.listPIMLists() to search for the system-assigned name for the contact list that you want to display.
  4. Invoke BlackBerryPIMList.getPIMListUID() to return the UID for contact list.
    long uid = cl.getPIMListUID();
  5. Invoke PIM.getInstance() to retrieve a PIM instance, and invoke PIM.openPIMList(int, int, long) to open the contact list, 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 UID.
    BlackBerryContactList list = (BlackBerryContactList) 
        PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE, uid);
    
  6. Invoke BlackBerryContactList.choose() to return a BlackBerryContact or a BlackBerryContactGroup PIMItem.
    PIMItem item = list.choose(); 
    if (item instanceof BlackBerryContact)
    {
         BlackBerryContact contact = (BlackBerryContact) item;
         int values = contact.countValues(BlackBerryContact.EMAIL);
         String email = contact.getString(BlackBerryContact.EMAIL, 0);
         System.out.println("Email is: " + email);
    }
    else if (item instanceof BlackBerryContactGroup)
    {
    ...
    }
  7. Check for PIMException, and check for ControlledAccessException if your application does not have permission to access the application that it invokes.

Was this information helpful? Send us your comments.