Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
mbasheerk
Posts: 326
Registered: ‎02-02-2009
My Device: Not Specified
Accepted Solution

Get the calendar item to our application

Hi, Friends 

 

when a message is added or deleted I  can know the event by folder listener!!!

How can I know a calendar item is added ?

can I get Save event of Calendar?

 

thanks in advance

Developer
mantaker
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Get the calendar item to our application

Duplicate post

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=38532#M38532

 

Please refrain from starting threads for same topic when one is active.. Rather you can "bump" up your thread to make it new..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
cream8tor
Posts: 30
Registered: ‎05-07-2009
My Device: Not Specified

Re: Get the calendar item to our application

[ Edited ]

 

Your application can register to be notified of calendar events added to, removed from, or updated in the calendar.  You need to implement net.rim.blackberry.api.pdap.PIMListListener, then open a javax.microedition.pim.EventList, cast the EventList to net.rim.blackberry.api.pdap.BlackBerryEventList, then add your listener by invoking addListener(PIMListListener) on the BlackBerryEventList.  Then the listener's itemAdded(), itemRemoved(), and itemUpdated() methods will be invoked when the corresponding events occur in the calendar, similar to FolderListener callbacks for email messages.

 

I threw together a little app that demonstrates this.  When it launches it shows an empty screen and registers a PIMListListener with an EventList.  Then, when items are added to, removed from, or updated in the BlackBerry Calendar application, the demo app will be notified and will add a message to the screen about the event that occurred and which calendar event was affected.  The logic to register the PIMListListener is in the runImpl() method.

 

 

 

import javax.microedition.pim.Event; import javax.microedition.pim.PIM; import javax.microedition.pim.PIMException; import javax.microedition.pim.PIMItem; import javax.microedition.pim.PIMList; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.RichTextField; import net.rim.device.api.ui.container.MainScreen; import net.rim.blackberry.api.pdap.BlackBerryEventList; import net.rim.blackberry.api.pdap.PIMListListener; public class CalendarListenerDemo extends UiApplication implements Runnable { private final MyPIMListListener _listener; private BlackBerryEventList _eventList; private final MainScreen _screen; public CalendarListenerDemo() { this._listener = new MyPIMListListener(); // override close() to unregister our listener when the app exits this._screen = new MainScreen() { public void close() { try { CalendarListenerDemo.this._eventList .removeListener(CalendarListenerDemo.this._listener); } catch (final Exception e) { // oh well } super.close(); } }; this._screen.setTitle("Calendar Listener Demo"); this.pushScreen(this._screen); } public void log(String message) { System.out.println(this.getClass().getName() + ": " + message); final RichTextField field = new RichTextField(message); this.invokeAndWait(new Runnable() { public void run() { CalendarListenerDemo.this._screen.add(field); } }); } private void logEvent(String eventName, PIMItem item) { final StringBuffer sb = new StringBuffer(); sb.append(eventName).append('('); if (item instanceof Event) { sb.append("Event["); if (item.countValues(Event.SUMMARY) > 0) { sb.append("SUMMARY=\""); sb.append(item.getString(Event.SUMMARY, 0)); sb.append('"'); } else if (item.countValues(Event.UID) > 0) { sb.append("UID=\""); sb.append(item.getString(Event.UID, 0)); sb.append('"'); } else { sb.append(item); } sb.append(']'); } else { sb.append(item); } sb.append(')'); this.log(sb.toString()); this.requestForeground(); } public void run() { while (!this.hasEventThread()) { Thread.yield(); } try { this.runImpl(); } catch (final Exception e) { this.log("ERROR: uncaught exception: " + e); e.printStackTrace(); } } private void runImpl() throws PIMException { final PIM pim = PIM.getInstance(); final PIMList pimList = pim.openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE); final BlackBerryEventList eventList = (BlackBerryEventList) pimList; this._eventList = eventList; final MyPIMListListener listener = this._listener; eventList.addListener(listener); this.log("EventList listener successfully registered"); } public static void main(String[] args) { final CalendarListenerDemo app = new CalendarListenerDemo(); new Thread(app).start(); app.enterEventDispatcher(); } private class MyPIMListListener implements PIMListListener { public void itemAdded(PIMItem item) { CalendarListenerDemo.this.logEvent("itemAdded", item); } public void itemRemoved(PIMItem item) { CalendarListenerDemo.this.logEvent("itemRemoved", item); } public void itemUpdated(PIMItem oldItem, PIMItem newItem) { CalendarListenerDemo.this.logEvent("itemUpdated", oldItem); } } }

 

 

 

Message Edited by cream8tor on 05-28-2009 12:06 PM