'How to filter-out rescheduled Android calendar events instances
I have an app that reads all calendar event instances for a time range like this:
...
fun getEventsInstancesForMultipleCalendars(context: Context, calendarsIds: List<Long>, from: Instant, to: Instant): Cursor? {
val builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
ContentUris.appendId(builder, from.toEpochMilli())
ContentUris.appendId(builder, to.toEpochMilli())
val selection = "${CalendarContract.Instances.CALENDAR_ID} IN (${calendarsIds.joinToString(", ") { "?" }})"
val selectionArgs = calendarsIds
.map { it.toString() }
.toTypedArray()
return context.contentResolver.query(builder.build(), EVENTS_INSTANCES_PROJECTION, selection, selectionArgs, null)
}
Everything is working fine, except for rescheduled instances of some recurring events. Both the rescheduled and the original event instances end-up in the result.
How can I filter-out the original event instance, which is no longer valid? Google Calendar correctly does not display the original instance, so there must be a way to do this.
I loaded every column from the calendar and the only difference between these instances I see, is, that they have different event_id and different _sync_id. And the only connection between them is that the new, now valid instance, has original_sync_id set to the original's _sync_id. This OK for cases when both, the old and new, event instances fall between my time range. But how do I check, and filter-out, rescheduled events if the new instance is not in the time range? Is there any query parameter I could add to the builder that will filter-our rescheduled events?
Other properties like deleted, visible, status, etc. have the same values in both instances.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
