Help Center
Local Navigation
- Integrating with BlackBerry Device Software applications
- Unified search
- Device interaction support
- Message list
- Custom messages
- Attachments
- Calendar
- Contact list
- Multiple contact lists support
- Open the contacts application
- Open the contacts application by using contact data
- Open the contacts application with a specific contact list
- Create a contact and assign it to a contact list
- Retrieve contact information
- Retrieve a contact list UID
- Export a contact
- Import a contact
- Delete a contact
- Notify an application when a contact list changes
- Creating and removing contact lists
- Retrieve the contact that is associated with an active call
- Retrieve the contact that is associated with a completed call
- Retrieve contacts by phone number
- Linking third-party contacts with contacts in the Contacts application
- Task list
- Phone
- BlackBerry Browser
- Menu items
- Find more information
- Glossary
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
Integration - BlackBerry Java SDK - 6.0
Create a contact and assign it to a contact list
You can create a contact and assign it to either the default contact list or another contact list on a BlackBerry® device.
- Import the required classes and interfaces.
import net.rim.blackberry.api.pdap.BlackBerryContact; import net.rim.blackberry.api.pdap.BlackBerryContactList; import net.rim.blackberry.api.pdap.BlackBerryPIMList; import net.rim.device.api.system.ControlledAccessException; import javax.microedition.pim.PIM; import javax.microedition.pim.PIMList; import javax.microedition.pim.PIMException; import javax.microedition.pim.ContactList;
- To add the new contact to 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 PIM.READ_WRITE
access mode. Proceed to step 4.
BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE); - To add the new contact to a contact list that is not the default contact list, perform the following actions:
- Invoke PIM.listPIMLists(int), passing in as the parameter the type of list (PIM.CONTACT_LIST), to return an array of String objects. The returned array provides the system-assigned names for each contact list. The default contact list is returned at index 0 of the array.
String[] lists = PIM.listPIMLists(PIM.CONTACT_LIST);
- Iterate over the array that PIM.listPIMLists() returns to search for the system-assigned name for the contact list that you want to open.
- 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 PIM.READ_WRITE
access mode, and the contact list name.
BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE, name);
- Invoke PIM.listPIMLists(int), passing in as the parameter the type of list (PIM.CONTACT_LIST), to return an array of String objects. The returned array provides the system-assigned names for each contact list. The default contact list is returned at index 0 of the array.
- Invoke ContactList.createContact() to add the new contact to the contact list.
BlackBerryContact contact = contactList.createContact();
- Invoke one or more of the following methods to add information for the new contact. For more information about PIMItem methods, see the API reference for the BlackBerry® Java® Development Environment.
- Invoke the following methods to verify that the information meets the size requirements and type requirements for the specified contact field.
- Invoke Contact.commit() to commit the changes.
if(contact.isModified()) { contact.commit(); } - Check for PIMException, and check for ControlledAccessException if your application does not have permission to access the application that it invokes.
Next topic: Retrieve contact information
Previous topic: Open the contacts application with a specific contact list