Creating All-Day Events Using Android Calendar Provider
<p>I would like my app to insert all day events into the calendar. I started off with the example given at <a href="https://developer.android.com/guide/topics/providers/calendar-provider.html" rel="nofollow">https://developer.android.com/guide/topics/providers/calendar-provider.html</a>. To make it all-day, I add the <code>ALL_DAY</code> content value and set the time zone to UTC. I end up with the folowing code:</p>

<pre><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);
</code></pre>

<p>Now, this actually does the job but the <code>DTEND</code> time seems redundant and setting start and end times meaningless when really only the date is needed. When I remove the <code>DTEND</code> value, I get an exception <code>java.lang.IllegalArgumentException: DTEND and DURATION cannot both be null for an event.</code>. What would be the proper values? Just arbitrary as above or could/should this actually be done with meaningful information?</p>