开发者

Using PIM, how to detect what is the attribute which is retrieved using Contact.TEL and index?

开发者 https://www.devze.com 2023-04-10 06:36 出处:网络
I\'m looping over all attributes ofthe Contact.TEL field to retrieve names and data, so that I can display something like this:

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 开发者_Go百科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)
    }
}


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

精彩评论

暂无评论...
验证码 换一张
取 消