StackTips

How to Add an Event to Android Calendar

stacktips avtar

Written by

Editorial,  1 min read,  2.8K views, updated on Sept. 17, 2023

The following code snippet shows how to add event in Android calendar using intent method.

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI)
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, eventDate.getTimeInMillis())
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, eventDate.getTimeInMillis() + 60 * 60 * 1000)
intent.putExtra(CalendarContract.Events.TITLE, title)
intent.putExtra(CalendarContract.Events.DESCRIPTION, description)
intent.putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_BUSY);
context.startActivity(intent);

Toast.makeText(context, "Event added to calendar, Toast.LENGTH_SHORT).show();