我正在使用此代码段来检索联系人的电子邮件收件人,但我要做的是列出已收到电子邮件地址的联系人。使用此方法,它会显示所有联系人
try {
list = (BlackBerryContactList) PIM.getInstance()
.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
PIMItem contact = list.choose();
if (contact != null) {
String emailId = "";
for (int i = 0; i < contact.countValues(Contact.EMAIL); i++) {
emailId = contact.getString(Contact.EMAIL, i);
System.out.println("_ _ _ _ __ EMAIL : " + i + " " + emailId);
}
}
} catch (PIMException e) {
Dialog.inform("Proble creating contact list!");
e.printStackTrace();
}
答案 0 :(得分:1)
在下面找到仅返回包含电子邮件地址的联系人列表的函数:
/*import email id from the contact list. */
public Vector getEmail()
{
Vector emailList=new Vector();//contains the list of contact
email_list.removeAllElements();
try
{
PIM pim = PIM.getInstance();
ContactList contacts;
contacts = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
Enumeration items;
items = contacts.items();
while(items.hasMoreElements())
{
Contact contact = (Contact) items.nextElement();
String emailID = "";
if (contacts.isSupportedField(Contact.EMAIL) && (contact.countValues(Contact.EMAIL) > 0) )
{
emailID=contact.getString(Contact.EMAIL, 0);
//emailList.addElement(arr);
}
String firstName = "";
if ((contacts.isSupportedField(Contact.NAME)) && (contact.countValues(Contact.NAME) > 0))
{
String[] name = contact.getStringArray(Contact.NAME, 0);
firstName = name[Contact.NAME_GIVEN];
// String lastName = name[Contact.NAME_FAMILY];
}
String arr[]={emailID,firstName};//array which contains emailid and first name
emailList.addElement(arr);
}
}
catch(Exception pe)
{
}
return emailList;
}