No answer according to the method I pointed out, but another way I found to add event with reminders to the calendar.
Hereunder methods are working fine for me :
// Add an event to the calendar of the user.
public void addEvent(Context context) {
GregorianCalendar calDate = new GregorianCalendar(this._year, this._month, this._day, this._hour, this._minute);
try {
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.DTSTART, calDate.getTimeInMillis());
values.put(CalendarContract.Events.DTEND, calDate.getTimeInMillis()+60*60*1000);
values.put(CalendarContract.Events.TITLE, this._title);
values.put(CalendarContract.Events.CALENDAR_ID, 1);
values.put(CalendarContract.Events.EVENT_TIMEZONE, Calendar.getInstance()
.getTimeZone().getID());
System.out.println(Calendar.getInstance().getTimeZone().getID());
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
// Save the eventId into the Task object for possible future delete.
this._eventId = Long.parseLong(uri.getLastPathSegment());
// Add a 5 minute, 1 hour and 1 day reminders (3 reminders)
setReminder(cr, this._eventId, 5);
setReminder(cr, this._eventId, 60);
setReminder(cr, this._eventId, 1440);
} catch (Exception e) {
e.printStackTrace();
}
}
// routine to add reminders with the event
public void setReminder(ContentResolver cr, long eventID, int timeBefore) {
try {
ContentValues values = new ContentValues();
values.put(CalendarContract.Reminders.MINUTES, timeBefore);
values.put(CalendarContract.Reminders.EVENT_ID, eventID);
values.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
Uri uri = cr.insert(CalendarContract.Reminders.CONTENT_URI, values);
Cursor c = CalendarContract.Reminders.query(cr, eventID,
new String[]{CalendarContract.Reminders.MINUTES});
if (c.moveToFirst()) {
System.out.println("calendar"
+ c.getInt(c.getColumnIndex(CalendarContract.Reminders.MINUTES)));
}
c.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// function to remove an event from the calendar using the eventId stored within the Task object.
public void removeEvent(Context context) {
ContentResolver cr = context.getContentResolver();
int iNumRowsDeleted = 0;
Uri eventsUri = Uri.parse(CALENDAR_URI_BASE+"events");
Uri eventUri = ContentUris.withAppendedId(eventsUri, this._eventId);
iNumRowsDeleted = cr.delete(eventUri, null, null);
Log.i(DEBUG_TAG, "Deleted " + iNumRowsDeleted + " calendar entry.");
}
public int updateEvent(Context context) {
int iNumRowsUpdated = 0;
GregorianCalendar calDate = new GregorianCalendar(this._year, this._month, this._day, this._hour, this._minute);
ContentValues event = new ContentValues();
event.put(CalendarContract.Events.TITLE, this._title);
event.put("hasAlarm", 1); // 0 for false, 1 for true
event.put(CalendarContract.Events.DTSTART, calDate.getTimeInMillis());
event.put(CalendarContract.Events.DTEND, calDate.getTimeInMillis()+60*60*1000);
Uri eventsUri = Uri.parse(CALENDAR_URI_BASE+"events");
Uri eventUri = ContentUris.withAppendedId(eventsUri, this._eventId);
iNumRowsUpdated = context.getContentResolver().update(eventUri, event, null,
null);
// TODO put text into strings.xml
Log.i(DEBUG_TAG, "Updated " + iNumRowsUpdated + " calendar entry.");
return iNumRowsUpdated;
}
Hope this could help others that encountered the same problem I had :).
Alex.
Intent
and not directly adding it? – Breannebrear