public void setRemindar(String titleD,String msgD,final String Title ,final String Description,final String day ,final String month,final String year){
Calendar cal = Calendar.getInstance();
Uri EVENTS_URI = Uri.parse(getCalendarUriBase(AlAujairyHoneycombActivity.this) + "events");
ContentResolver cr = getContentResolver();
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day), 9, 0);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day), 10, 0);
endMillis = endTime.getTimeInMillis();
// event insert
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", Title);
values.put("allDay", 0);
values.put("dtstart", startMillis ); // event starts at 11 minutes from now
values.put("dtend", endMillis); // ends 60 minutes from now
values.put("description", Description);
values.put("visibility", 0);
values.put("hasAlarm", 1);
Uri event = cr.insert(EVENTS_URI, values);
// reminder insert
Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(AlAujairyHoneycombActivity.this) + "reminders");
values = new ContentValues();
values.put( "event_id", Long.parseLong(event.getLastPathSegment()));
values.put( "method", 1 );
values.put( "minutes", 10 );
cr.insert( REMINDERS_URI, values );
}
private String getCalendarUriBase(Activity act) {
String calendarUriBase = null;
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = null;
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://calendar/";
} else {
calendars = Uri.parse("content://com.android.calendar/calendars");
try {
managedCursor = act.managedQuery(calendars, null, null, null, null);
} catch (Exception e) {
}
if (managedCursor != null) {
calendarUriBase = "content://com.android.calendar/";
}
}
return calendarUriBase;
}
在清单中
<uses-permission android:name="android.permission.WRITE_CALENDAR" />