6

I know, I am not the first one who ask this. I found many questions in stack itself, like

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

Android Calendar Provider exception on recurring events

Android Calendar Specific Event Deletion

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

I am using calendar contract provider api for all operations (dont need support for older android versions). and its NOT A SYNC ADAPTER.
We are successful in deleting all events (By deleting the events from event table itself).
But when I try to delete an occurrence of event using the Events.CONTENT_EXCEPTION_URI (by inserting) All events are getting disappeared. Following 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 stores the details of an event from the instance table,

  • given the value args.put(Events.ORIGINAL_SYNC_ID, 1); directly, As I am not setting the sync id while creating the event and we don't need any sync operations

Insertion to the exception uri returns a new ID but this makes all events get disappeared.

what is wrong with the code.. please helps us, we welcomes all suggestions and advance thanks to all...

Community
  • 1
  • 1
Renjith K N
  • 2,613
  • 2
  • 31
  • 53
  • http://stackoverflow.com/questions/10462095/delete-only-one-instance-of-a-recurring-event-from-my-android-calendar One of the answers provides a possible (untested) solution. You have to create an exception event. – Emile Dec 02 '14 at 09:57
  • @Emile Thank you for you response, I have already saw taht one and following the same way, But it causes to delete all occurrence or a months events. Some time it behaves like after deletion no events will be returned from the instance table but after a few minutes it returns the event correctly on that time the event was deleted correctly (But it don't return any event immediately after deletion) .. Please share any idea you have.. its will be a very huge help for me.... – Renjith K N Dec 02 '14 at 10:08
  • To remove an occurence you need to update the EXDATE field. In your code you need to remove the "CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CANCELED" http://stackoverflow.com/questions/17289153/add-date-to-events-exdate-android-calendar-provider?rq=1 – Emile Dec 02 '14 at 10:19
  • Afraid i've not had to do this myself, but more links for reference. http://stackoverflow.com/questions/14522393/android-exdate-format-when-adding-a-calendar-event – Emile Dec 02 '14 at 10:21
  • @Emile I tried once by removing that status in that case in samsung galaxy duos device calendar the vent was listed as a septate event on the deleted day (Means Exception was created but event is still displayed).And for that second link i read some where we don't need to insert to exdate by ourself as its is handled by the Events.ExceptionURI itself..But I will give a try for that one manually... I am extremely thank full for your support... – Renjith K N Dec 02 '14 at 10:35

1 Answers1

0

Here are the basics (as I've answered here)

  1. Find the instance you want to delete. (using Instances.query())
  2. Create the exception URI with the event ID appended.
  3. Create ContentValues. Put your instance's BEGIN value as ...Events.ORIGINAL_INSTANCE_TIME. Put STATUS_CANCELED as ...Events.STATUS
  4. Now only insert(yourURI, yourValues) and that's it!
Community
  • 1
  • 1
Alex.F
  • 5,648
  • 3
  • 39
  • 63