How to delete a calendar entry?

I am trying to implement my first Android program. He should write calendar entries (I know, not the best task to start Andorid programming).

I tried:

Uri CALENDAR_URI = Uri.parse("content://calendar/events"); ContentResolver cr = getContentResolver(); cr.delete(CALENDAR_URI, null, null); // Delete all cr.delete(CALENDAR_URI, "calendar_id=1", null); // Delete all in default calendar cr.delete(CALENDAR_URI, "_id=1", null); // Delete specific entry 

Nothing succeeded. I still get "cannot delete this URL".

Inserting a calendar entry was simple:

 ContentValues values = new ContentValues(); values.put("calendar_id", 1); values.put("title", this.title); values.put("allDay", this.allDay); values.put("dtstart", this.dtstart.toMillis(false)); values.put("dtend", this.dtend.toMillis(false)); values.put("description", this.description); values.put("eventLocation", this.eventLocation); values.put("visibility", this.visibility); values.put("hasAlarm", this.hasAlarm); cr.insert(CALENDAR_URI, values); 

According to my insertion method, access to the calendar worked.

Thanks Arthur!

+2
source share
2 answers

OK, I have not tried:

 Uri CALENDAR_URI = Uri.parse("content://calendar/events"); int id = 1; // calendar entry ID Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id); cr.delete(uri, null, null); 

This is what I was missing:

 Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id); 

should result in content: // calendar / events / 1

Now my calendar is empty :-)

+8
source

The right way to remove things from the user calendar is to use the appropriate GData APIs and remove them from your Google Calendar. Manipulating a calendar application's content provider — how you are trying to do — is not part of the public API.

+1
source

Source: https://habr.com/ru/post/978464/


All Articles