An Android app can add a calendar event in two ways. The simplest and safest option opens the system calendar editor. Direct insertion through Calendar Provider offers more control but requires calendar permissions and account handling.
Option 1: open the calendar editor
This approach does not require calendar read or write permission because the user reviews and saves the event:
1 | val start = System.currentTimeMillis() + 60 * 60 * 1000 |
Use this unless silent, app-managed insertion is a real product requirement.
Option 2: insert directly
Declare permissions in AndroidManifest.xml:
1 | <uses-permission android:name="android.permission.READ_CALENDAR" /> |
On Android 6.0 and later, request both dangerous permissions at runtime. After permission is granted, select a writable calendar from CalendarContract.Calendars, then insert the event:
1 | val zone = TimeZone.getDefault().id |
Add a reminder for that event:
1 | val reminder = ContentValues().apply { |
Calendar availability is not guaranteed. A device may have no writable account, a provider may reject a reminder method, or the user may revoke permission. Query for CAL_ACCESS_LEVEL >= CAL_ACCESS_CONTRIBUTOR, handle empty results, and show a clear fallback instead of assuming a fixed calendar ID.