Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just managed to add a Calendar using the new API from ICS. Stefan's answer helped, but to be able to write to all columns, you have to do the operation as a sync adapter. You can do this from a normal app using CalendarContract.ACCOUNT_TYPE_LOCAL. The following code should work on ICS. Maybe some column values are not right. Check out the documentation of CalendarContract.Calendars. Unfortunately I cannot help you for older Android versions, but CalendarContract is only used for some constant string values. Maybe these also work on older versions.</p> <pre><code>Uri calUri = CalendarContract.Calendars.CONTENT_URI; ContentValues cv = new ContentValues(); cv.put(CalendarContract.Calendars.ACCOUNT_NAME, yourAccountName); cv.put(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL); cv.put(CalendarContract.Calendars.NAME, yourInternalName); cv.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, yourDisplayName); cv.put(CalendarContract.Calendars.CALENDAR_COLOR, yourColor); cv.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER); cv.put(CalendarContract.Calendars.OWNER_ACCOUNT, true); cv.put(CalendarContract.Calendars.VISIBLE, 1); cv.put(CalendarContract.Calendars.SYNC_EVENTS, 1); calUri = calUri.buildUpon() .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT_NAME) .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL) .build(); Uri result = this.getContentResolver().insert(calUri, cv); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload