【问题标题】:Blackberry - get contacts list黑莓 - 获取联系人列表
【发布时间】:2010-01-20 06:10:52
【问题描述】:

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

提前谢谢...

【问题讨论】:

    标签: blackberry addressbook contacts


    【解决方案1】:

    试试这个代码:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 2016-10-08
      • 1970-01-01
      相关资源
      最近更新 更多