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
New Developer
Posts: 31
Registered: ‎08-02-2010
My Device: 9500
My Carrier: Developer

How to get all contacts in the black berry addressbook

Hi,

 

 

I hav seen the code to get a single contact into my application(by opening the address book and by selecting a single contact.).I dont want to open the address book. just i need the entire contacts in a vector.i want to display all the contacts as a list and perform user defined operations in my application.

 

 

so, how to get all the contacts in the address book  into my application.

 

I am using BlackBerryAPI 5.0

 

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to get all contacts in the black berry addressbook

To get all the Contact, this code is usefull for u,

This is the code which fetch all the first name and last Name.

 

 

           PIM pim = PIM.getInstance();
            BlackBerryContactList contacts = (BlackBerryContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
            Enumeration items = contacts.items(BlackBerryContactList.SEARCH_CONTACTS);
            while (items.hasMoreElements())
            {
                contact = (BlackBerryContact) items.nextElement();
                // Get first name and last name From Contact List
                String displayName = null;
                if(contact.countValues(Contact.NAME) > 0)
                {                
                    String[] name = contact.getStringArray(Contact.NAME, 0);
                    String firstName = name[Contact.NAME_GIVEN];
                    String lastName = name[Contact.NAME_FAMILY];
                    //add(new RichTextField("First Name:"+firstName));
                    //add(new RichTextField("Last Name:"+lastName));

                    if (firstName != null && lastName != null) 
                    {
                        displayName = firstName + " " + lastName;
                    } 
                    else if (firstName != null) 
                    {
                        displayName = firstName;
                    } else if (lastName != null) 
                    {
                        displayName = lastName;
                    }

 

------------------------------------------------------------------------
Press Kudoes and Accept as solution Button, If u got Answer.

Thanks.

 

New Developer
Posts: 31
Registered: ‎08-02-2010
My Device: 9500
My Carrier: Developer

Re: How to get all contacts in the black berry addressbook

 

Thanks nitin ,

My problem has been solved but i am getting  arraybound out of index exception

when i try to retrive the mobile number related to contact.

 

 

when a contact is stored with only name and mobile number ,does the index of  ATTR.Mobile changes

can u suggest how to retrive mobile number from contact.

 

 

Thanks & Regards

 

Srikanth

Regular Contributor
Posts: 98
Registered: ‎08-31-2010
My Device: BB-9700
My Carrier: Airtel

Re: How to get all contacts in the black berry addressbook

You can use

 

 

 BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);

 

 

Enumeration enumx = contactList.items();

while

(enumx.hasMoreElements()){

BlackBerryContact c = (BlackBerryContact) enumx.nextElement();

 

 

 

 

 

 

String

[] contact = new String[3];

 

{

 

contact[2] = cell.toString();

}

if(contactList.isSupportedField(BlackBerryContact.TEL))String cell = c.getString(Contact.TEL,0);

}

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: How to get all contacts in the black berry addressbook

once you have your contact, you can do:

int numValues = numValues = bContact.countValues(BlackBerryContact.TEL);
for (int i = 0; i < numValues; i++) {
   if (bContact.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE) {
      mobile = bContact.getString(BlackBerryContact.TEL, i);
      break;
   }
}

 

Developer
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: How to get all contacts in the black berry addressbook

To retrieve the mobile number U have to

Do Somthing like this.

 

 

if(contact.countValues(Contact.ADDR) > 0)
{
name1=contact.getStringArray(Contact.ATTR_Mobile,0);
String country=name1[Contact.ADD if(contact.countValues(Contact.ATTR_Mobile) > 0)
{
name1=contact.getStringArray(Contact.ADDR,0);
String mno=name1[Contact.ATTR_Mobile];
}
}

------------------------------------------------------------------------
Press Kudoes and Accept as solution Button, If u got Answer.

Thanks.

 

 

New Contributor
Posts: 5
Registered: ‎01-31-2011
My Device: Not Specified

Re: How to get all contacts in the black berry addressbook

what is bcontcat in this.......please let me know

Contributor
Posts: 22
Registered: ‎05-04-2012
My Device: BlackBerry Torch 9800
My Carrier: MTN Nigeria

Re: How to get all contacts in the black berry addressbook

I want to save all contacts to a csv file... How will i go about creating the file and populate it with the contact details?
Highlighted
Contributor
Posts: 22
Registered: ‎05-04-2012
My Device: BlackBerry Torch 9800
My Carrier: MTN Nigeria

Re: How to get all contacts in the black berry addressbook