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.
how do I programmatically add an event to the user's calendar?
Is there a common API they all share?
No, no more than there is a "common API they all share" for Windows calendar apps. There are some common data formats (e.g., iCalendar) and Internet protocols (e.g., CalDAV), but no common API. Some calendar apps don't even offer an API.
If there are specific calendar applications you wish to integrate with, contact their developers and determine if they offer an API. So, for example, the Calendar application from the Android open source project, that Mayra cites, offers no documented and supported APIs. Google has even explicitly told developers to not use the techniques outlined in the tutorial Mayra cites.
Another option is for you to add events to the Internet calendar in question. For example, the best way to add events to the Calendar application from the Android open source project is to add the event to the user's Google Calendar via the appropriate GData APIs.
Android 4.0 (API Level 14) added a
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);