Tutorials Android How to Add an Event to Device Calendar in Android

How to Add an Event to Device Calendar in Android

In this post, we will learn how to add an event to your device calendar in android.

Android allows us to invoke activities from other application using intent. Here in this example, we will be using the appropriate intent to invoke the default calendar application, and pre-filled with event details. The user must confirm to add the event, or can change, edit any of the details associated with particular events.

Use the following code snippet to invoke the default calendar event.

Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);

The above snippet will invoke the calendar application with empty fields and allow user to enter the event details before adding. However, you can pre-fill the event details by passing the details in the form of intent extras. The Extras values describes the event details, such as event start time, event end time, event title, event description, etc.

The following two class are important to understanding for adding the events.

  1. CalendarContract : Defines the data model of calendar and event related information. This data is stored in a number of tables, listed below.
  2. CalendarContract.Events: This table holds the event-specific information. Each row in this table has the information for a single event—for example, event title, location, start time, end time, and so on. The event can occur one-time or can recur multiple times. Attendees, reminders, and extended properties are stored in separate tables. They each have an EVENT_ID that references the _ID in the Events table.

The following code bundle can be used to pass the information to calendar intent.

intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startTime);
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
intent.putExtra(Events.TITLE, "Neel Birthday");
intent.putExtra(Events.DESCRIPTION, "This is a sample description");
intent.putExtra(Events.EVENT_LOCATION, "My Guest House");
intent.putExtra(Events.RRULE, "FREQ=YEARLY");

Most of the statements except the RRULE are self explanatory. The RRULE defines the repeat frequency for the events and follows the standard iCalendar recurrence rule format (see RFC 5544 for details).

The output of the above code is as follows.

How to add event to calendar in Android

[download url=”https://github.com/javatechig/Add-Calendar-Event-Android”]
Newest Most Voted
Inline Feedbacks
View all comments
7 years ago


6 years ago
Reply to  m


4 years ago

How to read events from calendar?

Nihal Sarawgi
Nihal Sarawgi
4 years ago

How to access this with the help of calendar ?

Previous Post
8 Surefire Tips For Your Mobile App Success

8 Surefire Tips For Your Mobile App Success

Next Post
Android Developer Days 2015

Android Developer Days 2015 Waits You

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
Would love your thoughts, please comment.x