Today i am going to share knowledge on how to work with android calendar and how do to add reminder in calendar.
First we start with how to add event in calendar
For that i have do something like below.....
Here i hava take calendar_id as 1 because i want to add this event in device calendar only.
Now you can see your event in android device calendar
Now if you also want to add reminder for any calendar event then use below code it's easy
First we start with how to add event in calendar
For that i have do something like below.....
Uri uri_events; if(Build.VERSION.SDK_INT >= 8) { uri_events= Uri.parse("content://com.android.calendar/reminders"); } else { uri_events= Uri.parse("content://calendar/reminders"); }
ContentValues values_events = new ContentValues(); values_events.put("calendar_id", 1); values_events.put("title", subject); values_events.put("description", notes); values_events.put("eventLocation", location); values_events.put("hasAlarm", 1); values_events.put("dtstart", myCalendar.getTimeInMillis()); values_events.put("dtend", myCalendar.getTimeInMillis()+extra_time_milisec); Uri newEvant = contentResolver.insert(uri_events, values_events); int id = Integer.parseInt(newEvant.getLastPathSegment()); values.put(GlobalUtility.COL_CAL_EVENTS_ID, id); //use this function only if you want to add reminder for added event setReminder(reminders, id);
Here i hava take calendar_id as 1 because i want to add this event in device calendar only.
Now you can see your event in android device calendar
Now if you also want to add reminder for any calendar event then use below code it's easy
Uri uri_reminder ;
if(Integer.parseInt(Build.VERSION.SDK) >=8)
{ uri_reminder = Uri.parse(GlobalUtility.URI_REMINDER_8_UP);
}
else
{ uri_reminder = Uri.parse(GlobalUtility.URI_REMINDER_8_BELOW);
}
private void setReminder(String reminder,int eventid) { int rem_value = 0;
ContentValues events_values = new ContentValues(); events_values.put("event_id", eventid); events_values.put("method", 1); events_values.put("minutes", rem_value); contentResolver.insert(uri_reminder, events_values); }