Question

I'm looping over all attributes of the Contact.TEL field to retrieve names and data, so that I can display something like this:
HOME: +2034953213
WORK: +2033923959
MOBILE: +20179083008

I've retrived the values (+2034953213, +2033923959, +20179083008) successfully using PIM api, but I didn't know how to detect what are the attributes corresponding to the values which I retrieved: (HOME, WORK or MOBILE ...etc) ?

How Can I detect that +2034953213 is either the 'HOME' or 'WORK' or 'MOBILE' ?
Same question for the other retrieved values ?

Here's my code:

ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
Enumeration contactListItems = contactList.items();
while (contactListItems.hasMoreElements()) {
    Contact contact = (Contact)contactListItems.nextElement();
    int telephonesCount = contact.countValues(Contact.TEL);
    for(int i=0; i< telephonesCount; ++i) {
        String number = contact.getString(Contact.TEL, i); 
        // I want here to know what is the current attribute that i retrieved its value ?
        // I mean its value not its index (either HOME, WORK or MOBILE ...etc)
    }
}
Was it helpful?

Solution

Here's the answer for those who are interested:

ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
Enumeration contactListItems = contactList.items();
while (contactListItems.hasMoreElements()) {
    Contact contact = (Contact)contactListItems.nextElement();
    int telephonesCount = contact.countValues(Contact.TEL);
    for(int i=0; i< telephonesCount; ++i) {
        String number = contact.getString(Contact.TEL, i); 
        int attribute = contact.getAttributes(BlackBerryContact.TEL, i);
        if (attribute == Contact.ATTR_MOBILE)
            // It's a mobile phone number, do whatever you want here ...
        else if (attribute == Contact.ATTR_HOME)
            // It's a home phone number, do whatever you want here ...
        else if (attribute == Contact.ATTR_WORK)
            // It's a work phone number, do whatever you want here ...
        // check other types the same way ...
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top