Tutorial details

Android Calendar API - Tutorial | App Code for Sale | Preview

Android Calendar API - Tutorial | Android Tutorial

How to use the Android Calendar API in Android 4.0

Overview PAGE TOP

Lars Vogel

Version 0.3

Copyright © 2012, 2013 Lars Vogel



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).

1. Prerequisites for this tutorial PAGE TOP

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 PAGE TOP

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);

Reference PAGE TOP


0 Comments Leave a comment

Please login in order to leave a comment.

Newest first

to your Chupamobile Account.

The Easiest way to Launch your next App or Game.

Join Chupamobile and get instant access to thousands of ready made App and Game Templates.

Creating an account means you’re okay with Chupamobile’s Terms of Service and Privacy Policy.