I searched the Internet many times and many examples. I can successfully add an event to the calendar through my application, but I cannot delete this event programmatically. Here are the samples that I tried that I cannot get a successful result.
tokens [1] is the identifier of the event.
1)
Uri eventsUri = Uri.parse(getCalendarUriBase()+"events"); Uri eventUri = ContentUris.withAppendedId(eventsUri, Long.parseLong(tokens[1])); getContentResolver().delete(eventUri, null, null);
2)
ContentResolver cr = FlightOperationsCancelTicketFee.this.getContentResolver(); Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events"); deleteEvent(cr, EVENTS_URI, 1); private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId) { Cursor cursor; if (android.os.Build.VERSION.SDK_INT <= 7) { cursor = resolver.query(eventsUri, new String[]{ "_id" }, "Calendars_id=" + calendarId, null, null); } else { cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + calendarId, null, null); } while(cursor.moveToNext()) { long eventId = cursor.getLong(cursor.getColumnIndex("_id")); resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null); } cursor.close(); }
3)
ContentResolver cr = getContentResolver(); String calUriString = "content://com.android.calendar/events"; Uri cal=Uri.parse(calUriString); String[] EVENT_PROJECTION=new String[]{"calendar_id","title","dtstart","_id"}; Uri eventsUri = Uri.parse(getCalendarUriBase()+"events"); Uri eventUri =ContentUris.withAppendedId(eventsUri, Long.parseLong(tokens[1])); String reminderUriString = "content://com.android.calendar/reminders"; Uri remUri =Uri.parse(reminderUriString); cr.delete(remUri, "event_id="+Commons.event_id, null); cr.delete(eventUri, null, null);
4)
Uri eventsUri = Uri.parse(getCalendarUriBase()+"events"); Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, Long.parseLong(tokens[1])); getContentResolver().delete(eventUri, null, null);
None of the above actions work. I need help. Thanks .. Edit: I think I can not send the correct context, is there a way to save the context using general settings? However, it only stores the values โโof String and Int. Is there any other way to do something like this?