• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4237
  • Last Modified:

How do I set an Alarm for a Calendar Event using iCal4j?

I am trying to find a simple example of how to add an alarm (or reminder) to an iCal event using iCal4j library.  I would like the alarm to be set 1 hour before the event.  I even know what I want the code to generate (see below), but can't figure out how to make iCal4j do it!

BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:REMINDER
TRIGGER;RELATED=START:-P1DT00H00M00S
END:VALARM

I have simple code below that works great, but there is no alarm component.  The API for iCal4j is not very good and I can't find any examples using google.  Can someone help with this?



private String getIcal2(String from, String to, Date eventDay, String subject,
		String body, String rmdrSummary, String rmdrLocation, String rmdrDescription) {
	
	// Clean up startDate for "all day" event
	Date startDate;
	Date endDate;
	Calendar cal = Calendar.getInstance();
	cal.setTime(eventDay);
	cal.set(Calendar.AM_PM, Calendar.AM);
	cal.set(Calendar.HOUR, 0);
	cal.set(Calendar.MINUTE, 0);
	cal.set(Calendar.SECOND, 0);
	cal.set(Calendar.MILLISECOND, 0);
	startDate = new Date(cal.getTimeInMillis());
	cal.add(Calendar.DATE, 1);
	endDate = new Date(cal.getTimeInMillis());
	
	CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY, true);
	
	// Create Calendar
	net.fortuna.ical4j.model.Calendar cal4j = new net.fortuna.ical4j.model.Calendar();
	cal4j.getProperties().add(new ProdId("-//AFrameSoftware//iCal4j 1.0//EN"));
	cal4j.getProperties().add(net.fortuna.ical4j.model.property.Version.VERSION_2_0);
	cal4j.getProperties().add(CalScale.GREGORIAN);
	cal4j.getProperties().add(net.fortuna.ical4j.model.property.Method.REQUEST);

	// Create event
	VEvent vEvent = new VEvent();
	vEvent.getProperties().add(new Uid("1234"));
	vEvent.getProperties().add(new Summary(rmdrSummary));
	vEvent.getProperties().add(new Description(rmdrDescription));
	vEvent.getProperties().add(new Location(rmdrLocation));
	vEvent.getProperties().add(new DtStart(new DateTime(startDate)));
	vEvent.getProperties().add(new DtEnd(new DateTime(endDate)));
	vEvent.getProperties().add(new XProperty("X-MICROSOFT-CDO-ALLDAYEVENT","TRUE"));
	vEvent.getProperties().add(new XProperty("X-MICROSOFT-CDO-INTENDEDSTATUS","FREE"));
	
	// !!! ADD ALARM HERE !!!
	
	// Attach Event to calendar
	cal4j.getComponents().add(vEvent);

	return cal4j.toString();

}

Open in new window

0
burtonrhodes
Asked:
burtonrhodes
1 Solution
 
for_yanCommented:


Seems to be like that;

http://m2.modularity.net.au/projects/ical4j/apidocs/


Example 1 - Creating an alarm to trigger at a specific time:


 java.util.Calendar cal = java.util.Calendar.getInstance();
 cal.set(java.util.Calendar.MONTH, java.util.Calendar.DECEMBER);
 cal.set(java.util.Calendar.DAY_OF_MONTH, 25);

 VAlarm christmas = new VAlarm(cal.getTime());
 

Example 2 - Creating an alarm to trigger one (1) hour before the scheduled start of the parent event/the parent todo is due:


 VAlarm reminder = new VAlarm(new Dur(0, -1, 0, 0));

 // repeat reminder four (4) more times every fifteen (15) minutes..
 reminder.getProperties().add(new Repeat(4));
 reminder.getProperties().add(new Duration(new Dur(0, 0, 15, 0)));

 // display a message..
 reminder.getProperties().add(Action.DISPLAY);
 reminder.getProperties().add(new Description("Progress Meeting at 9:30am"));
 
0
 
burtonrhodesAuthor Commented:
Not sure how I missed that?!!?  Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now