Thursday 19 March 2009

Add contacts in Blackberry

This code add 500 random contacts into the Blackberry phone.

ContactList blackBerryContactList = null;
try {
blackBerryContactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);

//Create 500 contacts
for (int i=0;i<250;i++)
{
Contact contact = blackBerryContactList.createContact();
String[] newName = new String[blackBerryContactList.stringArraySize(Contact.NAME)];
newName[Contact.NAME_PREFIX] = "";
newName[Contact.NAME_GIVEN] = new String(new char[]{(char)i});
newName[Contact.NAME_FAMILY] = ""+i;
contact.addStringArray(Contact.NAME,Contact.ATTR_NONE,newName);
contact.commit();
}

Enumeration allContacts = blackBerryContactList.items();
m_cache = enumToVector(allContacts);
m_listField.setSize(m_cache.size());

}catch(PIMException e)
{
Dialog.alert(e.toString());
}
finally{
if(blackBerryContactList !=null){
try {
blackBerryContactList.close();
} catch (PIMException e)
{

}
}
}

No comments: