Remove a contact list
You can remove contact lists from a
BlackBerry® device.
Note the following about removing contact lists:
- You cannot remove contact
lists that have service records.
- You cannot remove the last
remaining contact list on a device.
- You cannot remove the
default contact list (which has the UID -1).
A
BlackBerryPIMRemovalException is thrown if an error
occurs when you try to remove a contact list.
-
Import the required classes and interfaces.
import javax.microedition.pim.PIM;
import net.rim.blackberry.api.pdap.BlackBerryPIM;
import net.rim.blackberry.api.pdap.BlackBerryPIMRemovalException;
-
Retrieve a
BlackBerryPIM object.
BlackBerryPIM myPIM = (BlackBerryPIM) PIM.getInstance();
-
If you know the name or UID of the contact list that you want to
remove, go to step 6.
-
Retrieve the array of contact lists.
String[] lists = myPIM.listPIMLists(PIM.CONTACT_LIST);
The returned array provides the names that are assigned to
each contact list.
-
Iterate through the array to search for the contact list that you
want to remove.
-
Remove the contact list by invoking
BlackBerryPIM.removePIMList(). You can provide
either the name or the UID of the contact list. By default, the method removes
a contact list only if the list is empty. If you want to remove a contact list
that is not empty, you must provide the parameter
BlackBerryPIM.REMOVE_NON_EMPTY_LIST.
try
{
myPIM.removePIMList(PIM.CONTACT_LIST, "test",
BlackBerryPIM.REMOVE_NON_EMPTY_LIST);
}
catch (BlackBerryPIMRemovalException e)
{
// handle the exception
}
Code sample
BlackBerryPIM myPIM = (BlackBerryPIM) PIM.getInstance();
try
{
myPIM.removePIMList(PIM.CONTACT_LIST, "test", BlackBerryPIM.REMOVE_NON_EMPTY_LIST);
}
catch (BlackBerryPIMRemovalException e)
{
System.out.println(e.getMessage());
}
Was this information helpful? Send us your comments.