Android: deleting an event event deletes all its occurrence

I know, I'm not the first to ask about this. I found many questions on the stack itself , for example

Delete only one instance of a recurring event from my Android calendar

Android Calendar Provider Exception on Repeating Events

Remotely delete Android events for Android

but none of the above solved the problem . Now to my code.

I use the api calendar contract provider for all operations (do not need support for older versions of Android). and its NOT a SYNC ADAPTER .
We will be able to delete all events (by deleting events from the event table itself).
But when I try to delete the event of an event using Events.CONTENT_EXCEPTION_URI (by pasting) All events disappear, Below is my code

ContentValues args = new ContentValues(); args.put(Events.TITLE, eNote.getEventTitle()); args.put(Events.DTSTART, eNote.getStartTimeMill()); args.put(CalendarContract.Events.ORIGINAL_INSTANCE_TIME, eNote.getStartTimeMill()); args.put(Events.ORIGINAL_SYNC_ID, 1); args.put(Events.HAS_ALARM, "0"); args.put(Events.HAS_ATTENDEE_DATA,"0"); args.put(CalendarContract.Events.EVENT_TIMEZONE, eNote.getTimeZone()); args.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CANCELED); Uri.Builder eventUriBuilder = CalendarContract.Events.CONTENT_EXCEPTION_URI.buildUpon(); ContentUris.appendId(eventUriBuilder, eventID); try { final Uri resultUri = activity.getContentResolver().insert(eventUriBuilder.build(), args); int eventIDNew = Integer.parseInt(resultUri.getLastPathSegment()); Log.i(Global.DEBUG_TAG,"eventIDNew : " +eventIDNew); } catch (Exception e) { e.printStackTrace(); Log.i(Global.DEBUG_TAG, "Eroor : " +e.getMessage() ); } 
  • eNote is an object that stores event information from an instance table,

  • given the value of args.put (Events.ORIGINAL_SYNC_ID, 1); directly, since I do not set the synchronization identifier when creating the event, and we do not need any synchronization operations

Inserting uri into the exception returns a new identifier, but this causes all events to disappear.

what's wrong with the code .. please help us, we welcome all suggestions and thank everyone in advance ...

+6
source share
1 answer

Here is the basic information (as I answered here )

0
source

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


All Articles