1

I am working with a local calendar. Here is my code to create an event:

ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, 1457926200000L);
values.put(CalendarContract.Events.DURATION, "P3600S");
values.put(CalendarContract.Events.RRULE, "FREQ=DAILY;COUNT=2;WKST=SU");
values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
values.put(CalendarContract.Events.CALENDAR_ID, 34);
values.put(CalendarContract.Events.EXDATE, "20160314T033000Z");
values.put(CalendarContract.Events.TITLE, "R0");

Uri uri = getContentResolver().insert(CalendarContract.Events.CONTENT_URI, values);

Event is inserted correctly and while the COUNT is 2 in RRULE, I see just one event because of ExDate. But if I remove this line:

values.put(CalendarContract.Events.EXDATE, "20160314T033000Z");

And update the inserted event:

ContentValues values = new ContentValues();
values.put(CalendarContract.Events.EXDATE, "20160314T033000Z");
int update = getContentResolver().update(ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, 3612), values, null, null);

Event is updated successfully (I query that and ExDate is updated correctly). However I see 2 events instead of one and it seems that ExDate is not working.

I know that it is possible to insert exception using original_id and original_instance_time and CONTENT_EXCEPTION_URI. I want to know is there any other way to do that instead of inserting another event?

Thanks

Misagh Emamverdi
  • 3,654
  • 5
  • 33
  • 57

1 Answers1

1

Try adding CalendarContract.Events.DTSTART to the ContentValues when you update the event (make sure you pass the original value).

As you can see in CalendarInstancesHelper.java, the instances table update is skipped if DTSTART is not present in the modified ContentValues.

Marten
  • 3,802
  • 1
  • 17
  • 26
  • You are right. In addition to `DTSTART` I must include other related values (`RRULE` and `DURATION`). With these 4 values the result was OK. Thank you very much. – Misagh Emamverdi Mar 15 '16 at 14:06