📚 Encyclopedia

Android · updated 2026-11-02

Building a calendar app on Android's calendar provider

androidcalendarcontractcontent-providerrecurrencerrulereminders

Android has a system calendar database, CalendarContract, that sync adapters (Google, Exchange, CalDAV) fill and write back to. A calendar app that keeps no database of its own and reads and writes only through it gets every synced account for free, and its edits sync back to the server. Justin's Calendar app (io.jhampton.calendar, Kotlin + Compose, 2026-10-27) is built that way; this is what it took.

Reading events

Writing events

A calendar for people with no account

If there is no writable calendar, create one: insert into Calendars with ACCOUNT_TYPE_LOCAL, using a URI with CALLER_IS_SYNCADAPTER=true plus the account name and type as query parameters (only a "sync adapter" may create calendars). It lives only on the phone.

Reminders

The provider schedules reminders itself and broadcasts EVENT_REMINDER (data content://com.android.calendar/<alarm time>). A receiver with that action and data filter looks up the due alerts in CalendarAlerts by ALARM_TIME and posts notifications. The stock calendar app also listens, so offer a switch to turn the app's own notifications off and avoid doubles. All-day reminders count back from the start of the day: "the day before at 9 AM" is 900 minutes (15 hours).

Integration

Layout math worth keeping

Day and week views place overlapping events in columns: sort by start, group events whose times chain-overlap into a cluster, and give each event the first column whose last event has ended; the cluster's column count sets the widths. Keep this pure (no Android types) so it is unit-testable.

See also

Linked from

Sources: calendar memory (calendar-app 0.1.0-0.4.0), repo ~/dev/calendar, tldr post #1871