5

What I've used as guidelines:

http://developer.android.com/guide/topics/providers/calendar-provider.html#events

http://developer.android.com/reference/android/provider/CalendarContract.Events.html

https://www.rfc-editor.org/rfc/rfc5545#section-3.8.5.3 (for RRULE)

What I have about the Event:

  • start date
  • recurring end date
  • frequency (every day/week/month/year)

What I need, considering:

  • start date: 11.06.2014 13:00
  • recurring frequency: "daily"
  • recurring end date: 14.06.2014 10:00

I need to add an Android event which lasts 1h every day from 11.06 to 14.06 (not inclusive - because start hour is higher than recurring end hour):

  • 11.06 13:00-14:00
  • 12.06 13:00-14:00
  • 13.06 13:00-14:00

What I have until now (ignore non-recurring events - everything works as expected in those cases):

...
ContentValues values = new ContentValues();
values.put(Events.DTSTART, event.getDate().getTime());
if (!event.isRecurring()) { // ignore
    values.put(Events.DTEND, event.getEndDate().getTime());
    values.putNull(Events.DURATION);
    values.putNull(Events.RRULE);
    values.putNull(Events.RDATE);
} else {
    values.putNull(Events.DTEND);
    values.put(Events.DURATION, "PT1H"); // set event duration as 1H - this is ok hardcoded
    values.put(Events.RDATE, event.getRecurringEnd().getTime()); // when the event should stop recurring
    values.put(Events.RRULE,
            Utils.getRRuleForRecurring(event.getRecurring()) + ";UNTIL=" + event.getRecurringEnd().getTime());  
}
values.put(Events.TITLE, event.getName());
values.put(Events.DESCRIPTION, event.getDescription() == null ? ""
        : event.getDescription());
values.put(Events.CALENDAR_ID, calendarId);
values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
...

RRule generate method:

public static String getRRuleForRecurring(String recurring) {
    recurring = recurring.toLowerCase();
    if (recurring.equals("every day")) {
        return "FREQ=DAILY";
    }
    if (recurring.equals("every month")) {
        return "FREQ=MONTHLY";
    }
    if (recurring.equals("every week")) {
        return "FREQ=WEEKLY";           
    }
    if (recurring.equals("every year")) {
        return "FREQ=YEARLY";
    }
    
    return "FREQ=DAILY";
}

What happens: nothing, no errors. But the events doesn't show in the calendar. Again, for the non-recurring ones it works as expected

Community
  • 1
  • 1
user1236048
  • 5,542
  • 7
  • 50
  • 87
  • 1
    have a look at this issue: http://stackoverflow.com/questions/28871921/add-weekly-event-to-calendar – Sun Jul 01 '15 at 11:48

0 Answers0