2010-01-20 99 views
1

我想獲得的所有名稱的列表,並在黑莓JDE 4.7聯繫人列表及其相應的電子郵件地址,任何人都可以使用代碼幫助獲得上述的東西..黑莓 - 獲取聯繫人列表

謝謝提前...

回答

11

試試這個代碼:

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; 
} 
相關問題