import java.util.Enumeration; import javax.microedition.pim.Contact; import javax.microedition.pim.ContactList; import javax.microedition.pim.PIMException; import javax.microedition.pim.PIMItem; import javax.microedition.pim.PIMList; import net.rim.blackberry.api.pdap.PIMListListener2; final class MyPIMListener implements PIMListListener2 { public void itemAdded(PIMItem item) { System.out.println("Contact Add"); if (item == null) { return; }else{ //Read newly added PIMItem } } public void itemRemoved(PIMItem item) { System.out.println("Contact Remove"); if (item == null) { return; }else{ //Read removed Item } } public void itemUpdated(PIMItem oldItem, PIMItem newItem) { System.out.println("Contact UPdate"); if (oldItem == null || newItem == null) { return; } itemRemoved(oldItem); itemAdded(newItem); } public void batchOperation(PIMList list) { if (list == null) { return; } try { ContactList contactList = (ContactList) list; Enumeration e = contactList.items(); while (e.hasMoreElements()) { Contact contact = (Contact) e.nextElement(); // ... } } catch (PIMException e) { System.out.println(e); } } }
Write following code to call Listener.
try{ MyPIMListener listener = new MyPIMListener(); ContactList contactList; contactList = (ContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY); BlackBerryPIMList blackberryContactList = (BlackBerryPIMList) contactList; blackberryContactList.addListener(listener); }catch(PIMException e){ System.out.println("ex. "+e); }
No comments:
Post a Comment