Используя PIM, как определить, какой атрибут извлекается с помощью Contact.TEL и индекса? - PullRequest
0 голосов
/ 02 октября 2011

Я перебираю все атрибуты поля Contact.TEL для извлечения имен и данных, чтобы я мог отобразить что-то вроде этого:
HOME: +2034953213
WORK: +2033923959
MOBILE: +20179083008

Я успешно извлек значения (+2034953213, +2033923959, +20179083008) с использованием API-интерфейса PIM, но я не сделал этого не знаю, как определить, какие атрибуты соответствуют значениям, которые я получил: (ДОМ, РАБОТА или МОБИЛЬ ... и т. д.)?

Как я могу определить, что +2034953213или «ДОМ» или «РАБОТА» или «МОБИЛЬНЫЙ»?
Тот же вопрос для других найденных значений?

Вот мой код:

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

1 Ответ

0 голосов
/ 05 октября 2011

Вот ответ для тех, кому интересно:

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