黑莓 - 获取联系人列表

发布于 2024-08-18 15:27:15 字数 83 浏览 1 评论 0原文

我想从黑莓 JDE 4.7 中的联系人列表中获取所有姓名及其相应电子邮件地址的列表,任何人都可以帮助获取上述内容的代码。

提前感谢...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世界和平 2024-08-25 15:27:15

试试这个代码:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文