黑莓 - 获取联系人列表 [英] Blackberry - get contacts list

查看:149
本文介绍了黑莓 - 获取联系人列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得的所有名称的列表,并在黑莓JDE 4.7联系人列表及其相应的电子邮件地址,任何人都可以用code有助于获取上述东西..

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

在此先感谢...

推荐答案

试试这个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;
}

这篇关于黑莓 - 获取联系人列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆