0

我正在遍历该Contact.TEL字段的所有属性以检索名称和数据,以便可以显示如下内容:
HOME: +2034953213
WORK: +2033923959
MOBILE: +20179083008

我已经检索了这些值(+2034953213、+2033923959、 +20179083008) 成功使用 PIM api,但我不知道如何检测与我检索到的值对应的属性是什么:(HOME、WORK 或 MOBILE ...等)?

我如何检测到 +2034953213 是 'HOME' 或 'WORK' 或 'MOBILE' ?
其他检索到的值也有同样的问题?

这是我的代码:

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)
    }
}
4

1 回答 1

0

以下是有兴趣的人的答案:

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 ...
    }
}
于 2011-10-04T22:08:47.040 回答