How to add calendar events in Android?
-
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:
how do I programmatically add an event to the user's calendar? Which 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 http://android-developers.blogspot.com/2010/05/be-careful-with-content-providers.html 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.
Peter Nelson at Stack Overflow Visit the source
Other answers
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);
oriharel
As of Android version 4.0 http://android-developers.blogspot.com/2011/10/ics-and-non-public-apis.html to interact with the available http://developer.android.com/reference/android/provider/CalendarContract.html.
tobsen
Google calendar is the "native" calendar app. As far as I know, all phones come with a version of it installed, and the default SDK provides a version. You might check out this http://www.developer.com/ws/article.php/3850276/Working-with-the-Android-Calendar.htm for working with it.
Mayra
Try this use this API in your code.. This will help u to insert event, event with reminder and event with meeting can be enabled... This api works for platform 2.1 and above Those who uses less then 2.1 instead of content://com.android.calendar/events use content://calendar/events public static long pushAppointmentsToCalender(Activity curActivity, String title, String addInfo, String place, int status, long startDate, int needReminder, int needMailService) { /***************** Event: note(without alert) *******************/ String eventUriString = "content://com.android.calendar/events"; ContentValues eventValues = new ContentValues(); eventValues.put("calendar_id", 1); // id, We need to choose from // our mobile for primary // its 1 eventValues.put("title", title); eventValues.put("description", addInfo); eventValues.put("eventLocation", place); long endDate = startDate + 1000 * 60 * 60; // For next 1hr eventValues.put("dtstart", startDate); eventValues.put("dtend", endDate); // values.put("allDay", 1); //If it is bithday alarm or such // kind (which should remind me for whole day) 0 for false, 1 // for true eventValues.put("eventStatus", status); // This information is // sufficient for most // entries tentative (0), // confirmed (1) or canceled // (2): eventValues.put("visibility", 3); // visibility to default (0), // confidential (1), private // (2), or public (3): eventValues.put("transparency", 0); // You can control whether // an event consumes time // opaque (0) or transparent // (1). eventValues.put("hasAlarm", 1); // 0 for false, 1 for true Uri eventUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues); long eventID = Long.parseLong(eventUri.getLastPathSegment()); if (needReminder != -1) { /***************** Event: Reminder(with alert) Adding reminder to event *******************/ String reminderUriString = "content://com.android.calendar/reminders"; ContentValues reminderValues = new ContentValues(); reminderValues.put("event_id", eventID); reminderValues.put("minutes", 5); // Default value of the // system. Minutes is a // integer reminderValues.put("method", 1); // Alert Methods: Default(0), // Alert(1), Email(2), // SMS(3) Uri reminderUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues); } /***************** Event: Meeting(without alert) Adding Attendies to the meeting *******************/ if (needMailService != -1) { String attendeuesesUriString = "content://com.android.calendar/attendees"; /******** * To add multiple attendees need to insert ContentValues multiple * times ***********/ ContentValues attendeesValues = new ContentValues(); attendeesValues.put("event_id", eventID); attendeesValues.put("attendeeName", "xxxxx"); // Attendees name attendeesValues.put("attendeeEmail", "[email protected]");// Attendee // E // mail // id attendeesValues.put("attendeeRelationship", 0); // Relationship_Attendee(1), // Relationship_None(0), // Organizer(2), // Performer(3), // Speaker(4) attendeesValues.put("attendeeType", 0); // None(0), Optional(1), // Required(2), Resource(3) attendeesValues.put("attendeeStatus", 0); // NOne(0), Accepted(1), // Decline(2), // Invited(3), // Tentative(4) Uri attendeuesesUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(attendeuesesUriString), attendeesValues); } return eventID; }
Pradeep
Related Q & A:
- How to update native calendar events programatically?Best solution by sharepoint.stackexchange.com
- How to query calendar with events from a specific date?Best solution by stackoverflow.com
- How to add calendar event in Yahoo calendar?Best solution by Stack Overflow
- How to add new view at the top of an existing view in Android?Best solution by Stack Overflow
- How to add this library project to Android Studio?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.