Blackberry - get contacts list

烂漫一生 提交于 2019-12-08 06:05:40

问题


I wanted to get the list of all names and their corresponding email address from the contact list in blackberry JDE 4.7 can anyone help with the code for getting the above mentioned things..

Thanks in advance...


回答1:


try this code:

public Scr() {
    Vector v = getContacts();
    Enumeration iterator = v.elements();
    while (iterator.hasMoreElements()) {
        String[] contact = (String[]) iterator.nextElement();
        for (int i = 0; i < contact.length; i++)
            add(new LabelField(contact[i]));
    }

}

private Vector getContacts() {
    Vector result = new Vector();
    try {
        BlackBerryContactList contactList = (BlackBerryContactList) PIM
                .getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
        Enumeration enumx = contactList.items();
        while (enumx.hasMoreElements()) {
            BlackBerryContact c = (BlackBerryContact) enumx.nextElement();
            String[] contact = new String[2];
            if (contactList.isSupportedField(BlackBerryContact.NAME)) {
                String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
                String firstName = name[Contact.NAME_GIVEN];
                String lastName = name[Contact.NAME_FAMILY];
                contact[0] = firstName + " " + lastName;
            }
            if (contactList.isSupportedField(BlackBerryContact.EMAIL)) {
                StringBuffer emails = new StringBuffer();
                int emailCount = c.countValues(BlackBerryContact.EMAIL);
                for (int i = 0; i < emailCount; i++) {
                    String email = c.getString(BlackBerryContact.EMAIL, i);
                    if (email != null) {
                        emails.append(email.trim());
                        emails.append("; ");
                    }
                }
                contact[1] = emails.toString();
            }
            result.addElement(contact);
        }
    } catch (PIMException ex) {
        ex.printStackTrace();
    }
    return result;
}


来源:https://stackoverflow.com/questions/2099387/blackberry-get-contacts-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!