StackTips
 1 minutes

How to Add an Event to Android Calendar

By Editorial @stacktips, On Sep 17, 2023 Android 2.38K Views

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(); 
stacktips avtar

Editorial

StackTips provides programming tutorials, how-to guides and code snippets on different programming languages.