Open the contacts application by using contact data

You can open the contacts application on a BlackBerry® device and display a contact by using the Invoke.invokeApplication() method, and passing in contact data as a parameter of an AddressBookArguments object.

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.invoke.AddressBookArguments;
    import net.rim.blackberry.api.invoke.Invoke;
    import net.rim.blackberry.api.pdap.BlackBerryContact;
    import net.rim.blackberry.api.pdap.BlackBerryContactList;
    import net.rim.device.api.system.ControlledAccessException;
    import javax.microedition.pim.PIM;
    import javax.microedition.pim.PIMException;
  2. Invoke PIM.getInstance() to retrieve a PIM instance, and invoke PIM.openPIMList(int, int) to open the default contact list, 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). To open a named contact list, you can instead invoke PIM.openPIMList(int, int, String).
    BlackBerryContactList contactList = (BlackBerryContactList) 
       PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
  3. Invoke BlackBerryContactList.getByUID(String uid) to retrieve a contact from the contact list.
    BlackBerryContact contact = contactList.getByUID("1XKIOD898");
  4. Create an instance of the AddressBookArguments class, passing in a Contact object as a parameter.
    AddressBookArguments abArg = new AddressBookArguments("ARG_VIEW", contact);
  5. Invoke Invoke.invokeApplication(APP_TYPE_ADDRESSBOOK, AddressBookArguments) and use the AddressBookArguments object for the contact.
    Invoke.invokeApplication(Invoke.APP_TYPE_ADDRESSBOOK, abArg);
  6. 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.