Sunday, March 28, 2010

contact number from phone book : using j2me

public static Vector retrieveContactInfo()
{
Vector vContactInfo = new Vector();

//Check that PIM Optional Package is available
String pimVersion = System.getProperty("microedition.pim.version");
if(pimVersion == null)
return null;
else
{
PIM pim = PIM.getInstance();
ContactList contactList = null;
try
{
contactList = (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
if(contactList == null)
{
return null;
}

Enumeration clEnum = contactList.items();
while(clEnum.hasMoreElements())
{
Contact contact = (Contact) clEnum.nextElement();
String name = "";

try
{
//if(contactList.isSupportedField(Contact.FORMATTED_NAME))
{
name = contact.getString(Contact.FORMATTED_NAME, 0);
}
}
catch(Exception ex) //An unexpected error occurred while reading the contact name.
{
continue;
}

if(!contactList.isSupportedField(Contact.TEL))
{
continue;
}

int noOfPhones = contact.countValues(Contact.TEL);
Vector vTelInfo = new Vector();
for(int i = 0; i < contactattribute =" contact.getAttributes(Contact.TEL," number =" contact.getString(Contact.TEL," teltype = "" contactattribute ="="" teltype = "Home" contactattribute ="="" teltype = "Mobile" contactattribute ="="" teltype = "Work" contactattribute ="="" teltype = "Other" contactattribute ="="" teltype = "Pager" contactattribute ="="" teltype = "General"> 0)
{
vContactInfo.addElement(new ContactInfo(name, vTelInfo));
}
}
}
catch (PIMException ex)
{
return null;
}
catch (SecurityException ex)
{
return null;
}

return vContactInfo;
}

No comments:

Post a Comment