I try add an event to blackberry calendar. The following code is used:
EventList eventList = (EventList)PIM.getInstance().openPIMList(PIM.EVENT_LIST,PIM.WRITE_ONLY);
_event = eventList.createEvent();
String subject = _subject.getText().trim();
String location = _location.getText().trim();
long startTime = _startTime.getDate();
long endTime = _endTime.getDate();
String description = _desc.getText().trim();
if (subject.length() == 0 || location.length() == 0)
{
Dialog.inform("Subject and location required");
return false;
}
if ( endTime <= startTime || startTime < System.currentTimeMillis())
{
Dialog.inform("Invalid Start/End times");
return false;
}
_event.addString(Event.SUMMARY, PIMItem.ATTR_NONE, subject );
_event.addString(Event.LOCATION, PIMItem.ATTR_NONE, location);
_event.addDate(Event.START, PIMItem.ATTR_NONE, startTime);
_event.addDate(Event.END, PIMItem.ATTR_NONE, endTime);
_event.addString(Event.NOTE, PIMItem.ATTR_NONE, description);
RepeatRule rule = new RepeatRule();
switch(_recur.getSelectedIndex())
{
case 1:
rule.setInt(RepeatRule.FREQUENCY,RepeatRule.DAILY);
break;
case 2:
rule.setInt(RepeatRule.FREQUENCY,RepeatRule.WEEKLY);
break;
case 3:
rule.setInt(RepeatRule.FREQUENCY,RepeatRule.MONTHLY);
break;
case 4:
rule.setInt(RepeatRule.FREQUENCY,RepeatRule.YEARLY);
break;
}
_event.setRepeat(rule);
_event.commit();
This code is taken from Blackberry Sample Application PIMDEMO
The error is :
The event added to the dates After the end date
Example:
If I set a event from 2011 Dec 1 (start date)to 2011 Dec 5(end date) Then the event shown in calendar from Dec 1 to all days after it(that is the event never ends).
I tested this code in simulator and BlackBerry pearl 9105.
Remove the Following
RepeatRuleCode and try.