I would like my app to insert all day events into the calendar. I started off with the example given at https://developer.android.com/guide/topics/providers/calendar-provider.html. To make it all-day, I add the ALL_DAY
content value and set the time zone to UTC. I end up with the folowing code:
long calID = 3;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(2012, 9, 14, 7, 30);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(2012, 9, 14, 8, 45);
endMillis = endTime.getTimeInMillis();
ContentResolver cr = getContentResolver();
values.put(Events.ALL_DAY, 1)
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DTEND, endMillis);
values.put(Events.TITLE, "Jazzercise");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "UTC");
Uri uri = cr.insert(Events.CONTENT_URI, values);
Now, this actually does the job but the DTEND
time seems redundant and setting start and end times meaningless when really only the date is needed. When I remove the DTEND
value, I get an exception java.lang.IllegalArgumentException: DTEND and DURATION cannot both be null for an event.
. What would be the proper values? Just arbitrary as above or could/should this actually be done with meaningful information?