Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
Accepted Solution

How to get contacts from all contact lists available in Address Book?

I want to programmatically retrieve the contacts from all the available contactlists in blackberry. Is it possible?

Please use plain text.
Developer
simon_hain
Posts: 16,209
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get contacts from all contact lists available in Address Book?

you can access the standard contact list using http://www.blackberry.com/developers/docs/7.1.0api/net/rim/blackberry/api/pdap/BlackBerryContactList...

just be warned, its not very fast. use a separate thread and test it with a big address book (somebody wrote a test program to fill it with 1k contacts i think, but i don't have the link in my knowledge base so you would have to see for yourself)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: How to get contacts from all contact lists available in Address Book?

i have three contact lists(with name email addresses) on my device. i am able to get a contact list from one list but not from other two i have try this using your link but not able to retreive other two lists till now
Please use plain text.
Developer
simon_hain
Posts: 16,209
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to get contacts from all contact lists available in Address Book?

http://www.blackberry.com/developers/docs/7.1.0api/javax/microedition/pim/PIM.html#listPIMLists(int) should give you a list of all, http://www.blackberry.com/developers/docs/7.1.0api/javax/microedition/pim/PIM.html#openPIMList(int,%... opens one by the name retrieved above.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: How to get contacts from all contact lists available in Address Book?

Done using below code, this code will remove all contacts from all contact lists

 try
 {
     PIM pim = PIM.getInstance();
     String[] list = pim.listPIMLists(PIM.CONTACT_LIST);// This Will Retreive all Contact lists
     for(int i = 0; i< list.length; i++)
     {
          ContactList contactList=(ContactList) pim.openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE, list[i]);
          Enumeration enum = contactList.items();
          while(enum.hasMoreElements())
          {
              contactList.removeContact((Contact) enum.nextElement());
         }    
     }

}
catch (Exception e)

{
}

Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: How to get contacts from all contact lists available in Address Book?

Thanks for help
Please use plain text.