How to add calendar events in Android?

Peter Nelson picture Peter Nelson · Sep 15, 2010 · Viewed 205.4k times · Source

I'm just getting up to speed on Android, and today in a project meeting someone said that Android has no native calendar app so users just use whatever calendar app they like.

Is this true, and if so how do I programmatically add an event to the user's calendar? Is there a common API they all share?

For what it's worth, we're probably targeting Android 2.x.

Answer

oriharel picture oriharel · Dec 2, 2010

Try this in your code:

Calendar cal = Calendar.getInstance();              
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
startActivity(intent);