【问题标题】:Using PIM, how to detect what is the attribute which is retrieved using Contact.TEL and index?使用 PIM,如何检测使用 Contact.TEL 和索引检索到的属性是什么?
【发布时间】:2011-10-05 06:08:47
【问题描述】:

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

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

我如何检测到 +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)
    }
}

【问题讨论】:

标签: blackberry java-me contacts contact-list pim


【解决方案1】:

这里是给感兴趣的人的答案:

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 ...
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2012-03-23
    • 2023-03-16
    • 2010-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多