如何过滤重新安排的Android日历事件实例

发布于 2025-01-20 23:35:32 字数 1209 浏览 0 评论 0原文

我有一个应用程序可以读取某个时间范围内的所有日历事件实例,如下所示:

...
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 中来过滤我们重新安排的事件?

其他属性(例如 deletedvisiblestatus 等)在两个实例中具有相同的值。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文