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...