• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4392
  • 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!


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.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"));

	// 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

	return cal4j.toString();


Open in new window

1 Solution

Seems to be like that;


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(new Description("Progress Meeting at 9:30am"));
burtonrhodesAuthor Commented:
Not sure how I missed that?!!?  Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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