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: 28
Registered: ‎08-19-2008
My Device: Not Specified

Problem of getting phone number from PIM list

I've added a menu item into Address book. When user clicks on it, it shows the phone numbers of this contact. Then user clicks on the phone number, the application will do some actions for the number.

 

I tested on device software 4.2 (8707), the contact has 3 phones - Work, Work 2 and Mobile. But my application shows "Work" and "Mobile" only, not "Work 2". And another test on 4.3 simulator (8120), it shows "Work" TWICE and "Mobile" once, not "Work 2" again.

 

Is there a bug for these device software?

 

Here is the code for reference.

 

if (context instanceof BlackBerryContact) {
            BlackBerryContact bbContact = (BlackBerryContact) context;
            PIMList pimList = bbContact.getPIMList();
            int phoneCount = bbContact.countValues(Contact.TEL);
            if (phoneCount > 0){
                String[] phoneNums = new String[phoneCount];
                String[] labels = new String[phoneCount];
                for (int i=0; i<phoneCount; i++) {
                    String phoneNum = bbContact.getString(Contact.TEL, i);
                    String label = pimList.getAttributeLabel(bbContact.getAttributes(Contact.TEL, i));
                    phoneNums[i] = phoneNum;
                    labels[i] = label + ": " + phoneNum;
                }
                if (phoneCount == 1) {
                    doSomething(phoneNums[0]);
                }  else {
                    int choice = Dialog.ask("Which number?", labels, 0);
                    if (choice >= 0) doSomething(phoneNums[choice]);
                }
            } else {
                Dialog.inform("No phone is stored for such contact!");
            }
}

Developer
Posts: 16,676
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Problem of getting phone number from PIM list

work2/home2 is not supported in all versions. in 4.6 the fields are listed, in 4.2.1 they are not. just look them up in BlackberryContact to see what OS versions grant access to them.
----------------------------------------------------------
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