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).
Unresolved directive in 001_article.adoc - include::../10_Include/prerequisites/android_prerequisite.adoc == 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); intent.setData(CalendarContract.Events.CONTENT_URI); startActivity(intent);
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.setType("vnd.android.cursor.item/event"); 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); intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis()); intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis()); // 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);
1. About this website
2. Links and Literature
2.1. Android Resources
http://www.vogella.com/tutorials/AndroidLocationAPI/article.html - Android Location API and Google Maps
http://www.vogella.com/tutorials/AndroidNetworking/article.html - Android and Networking
http://code.google.com/intl/de-DE/android/ - Android Homepage
http://code.google.com/p/android/issues/list - Android Issues / Bugs
http://groups.google.com/group/android-developers - Android Google Groups
2.2. vogella GmbH training and consulting support
|TRAINING||SERVICE & 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.
Appendix A: Copyright and License
Copyright © 2012-2016 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.