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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Create an Event within the Calendar application

by BlackBerry Development Advisor ‎02-16-2010 01:08 PM - edited ‎09-16-2010 02:58 PM

Summary

 

This article applies to the following:

 

  • BlackBerry® Java Development Environment (BlackBerry JDE) 4.0 or later
  • BlackBerry Device Software 4.0 or later



Description


BlackBerry JDE 4.0 introduced the personal digital assistance profile (PDAP) package (net.rim.blackberry.api.pdap) to allow access to the Calendar, Tasks, and Address Book applications on the BlackBerry device. This package replaces the net.rim.blackberry.api.pim package as it has been deprecated.

 

Included within the net.rim.blackberry.api.pdap package is the BlackBerryEvent interface, which represents an event contained in the default BlackBerry device calendar. This interface defines extended fields in the event, along with the standard fields obtained through the javax.microediition.pim.Event interface.

 

Using the BlackBerryEvent interface and Event/EventList interfaces, you can create calendar appointments within the Calendar application. The below sample explains how to create an all-day calendar event using the BlackBerryEvent.ALLDAY field attribute. This field attribute is a type boolean and indicates whether or not an event is an all-day event.

 

It is important to verify the field count on the ALLDAY field attribute to determine if this property has already been set. This will verify if the setBoolean() or addBoolean() method is required. An IndexOutOfBoundsException is possible if the wrong method (set/add) is called.

 

 

EventList _eventList = null;
try {
// Creates/Opens an instance of the specified PIM list (Event List) in Read/Write mode.
_eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST, PIM.READ_WRITE);

// Creates a new Event
BlackBerryEvent bbEvent = (BlackBerryEvent)_eventList.createEvent();



// Checks the Event List to determine if the ALLDAY field is supported
if(_eventList.isSupportedField(BlackBerryEvent.ALLDAY)) {
// Checks the event to determine if ALLDAY attribute as already be set
if(bbEvent.countValues(BlackBerryEvent.ALLDAY) > 0) {
bbEvent.setBoolean(BlackBerryEvent.ALLDAY,0,Event.ATTR_NONE,true);
} else {
bbEvent.addBoolean(BlackBerryEvent.ALLDAY,Event.ATTR_NONE,true);
}
}
} catch(PIMException e) {
// Handle Exception
}


Note: It is best practice to verify the validity of a field before setting or adding a value to the event by using the isSupportedField() method.

 


Additional Information


For additional details on how to create calendar events or other personal information management (PIM) related items, see BlackBerry Java Development Environment Development Guide, Chapter 11 – Using PIM applications.

 

 

Contributors