如何过滤重新安排的Android日历事件实例
我有一个应用程序可以读取某个时间范围内的所有日历事件实例,如下所示:
...
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)
}
除了某些重复事件的重新安排实例之外,一切都工作正常。重新安排的事件实例和原始事件实例最终都会出现在结果中。
如何过滤掉不再有效的原始事件实例? Google 日历正确地不会显示原始实例,因此必须有一种方法可以做到这一点。
我加载了日历中的每一列,我看到的这些实例之间的唯一区别是,它们具有不同的 event_id
和不同的 _sync_id
。它们之间的唯一联系是新的、现在有效的实例将 original_sync_id
设置为原始的 _sync_id
。对于新旧事件实例都落在我的时间范围内的情况,这没问题。但是,如果新实例不在时间范围内,我如何检查并过滤掉重新安排的事件?是否有任何查询参数可以添加到 builder
中来过滤我们重新安排的事件?
其他属性(例如 deleted
、visible
、status
等)在两个实例中具有相同的值。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论