Найдите ниже функцию, которая возвращает только те контакты, которые содержат адрес электронной почты:
/*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;
}