Support free tutorials

vogella training Training Books

Android Calendar API - Tutorial

Lars Vogel

Version 0.3


Using the Android Calendar API

This article describes how to use the Android Calendar API in Android 4.0. It is based on Eclipse 3.7, Java 1.6 and Android 4.0 (Ice Cream Sandwich).

Table of Contents

1. Prerequisites for this tutorial
2. Calendar API
3. About this website
3.1. Donate to support free tutorials
3.2. Questions and discussion
3.3. License for this tutorial and its code
4. Links and Literature
4.1. Source Code
4.2. Android Resources
4.3. vogella GmbH training and consulting support

1. Prerequisites for this tutorial

The following assumes that you have already basic knowledge in Android development. Please check the Android development tutorial to learn the basics.

2. Calendar API

The Calendar API is available as of Android 4.0.

Creating new events is done via Intents and does not require any permission. Setting properties of the event is done via Intent extras. The user will be prompted if the event should be created.

For example the following will prompt the user if an event should be created with certain details.

// ACTION_INSERT does not work on all phones
// use  Intent.ACTION_EDIT in this case
Intent intent = new Intent(Intent.ACTION_INSERT);

You can also add dates and time, if this event is repeated and the like. See the comments in the coding for examples.

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.putExtra(Events.TITLE, "Learn Android");
intent.putExtra(Events.EVENT_LOCATION, "Home suit home");
intent.putExtra(Events.DESCRIPTION, "Download Examples");

// Setting dates
GregorianCalendar calDate = new GregorianCalendar(2012, 10, 02);

// make it a full day event
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

// make it a recurring Event
intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");

// Making it private and shown as busy
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); 

3. About this website

3.1. Donate to support free tutorials

Please consider a contribution Support free tutorials if this article helped you. It will help to maintain our content and our Open Source activities.

3.2. Questions and discussion

Writing and updating these tutorials is a lot of work. If this free community service was helpful, you can support the cause by giving a tip as well as reporting typos and factual errors.

If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

3.3. License for this tutorial and its code

This tutorial is Open Content under the CC BY-NC-SA 3.0 DE license. Source code in this tutorial is distributed under the Eclipse Public License. See the vogella License page for details on the terms of reuse.

4. Links and Literature

4.1. Source Code

Source Code of Examples

4.3. vogella GmbH training and consulting support

The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”. The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.