Java tutorial
//package com.java2s; import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.net.Uri; import android.provider.CalendarContract.Events; import android.provider.CalendarContract.Reminders; import android.util.Log; import java.util.TimeZone; public class Main { private static final String DEBUG_TAG = "CalendarActivity"; private static Activity activityObj; public static void IcsMakeNewCalendarEntry(String title, String description, String location, long startTime, long endTime, int allDay, int hasAlarm, int calendarId, int selectedReminderValue) { ContentResolver cr = activityObj.getContentResolver(); ContentValues values = new ContentValues(); values.put(Events.DTSTART, startTime); values.put(Events.DTEND, endTime); values.put(Events.TITLE, title); values.put(Events.DESCRIPTION, description); values.put(Events.CALENDAR_ID, calendarId); if (allDay == 1) { values.put(Events.ALL_DAY, true); } if (hasAlarm == 1) { values.put(Events.HAS_ALARM, true); } //Get current timezone values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()); Log.i(DEBUG_TAG, "Timezone retrieved=>" + TimeZone.getDefault().getID()); Uri uri = cr.insert(Events.CONTENT_URI, values); Log.i(DEBUG_TAG, "Uri returned=>" + uri.toString()); // get the event ID that is the last element in the Uri long eventID = Long.parseLong(uri.getLastPathSegment()); if (hasAlarm == 1) { ContentValues reminders = new ContentValues(); reminders.put(Reminders.EVENT_ID, eventID); reminders.put(Reminders.METHOD, Reminders.METHOD_ALERT); reminders.put(Reminders.MINUTES, selectedReminderValue); Uri uri2 = cr.insert(Reminders.CONTENT_URI, reminders); } } }