Using PIM, how to detect what is the attribute which is retrieved using Contact.TEL and index?
I'm looping over all attributes of the Contact.TEL
field to retrieve names and data, so that I can display something like this:
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)
}
}
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 ...
}
}
精彩评论