如何获取日历事件标题为包括重复事件事件、日历、标题

2023-09-07 01:10:09 作者:耍酷小男人

我需要做一个并不复杂的事情,我们可以相信。我想从日历事件情况下我的手机上有事件的标题一起。我发现对堆栈溢出几个答案告诉查询实例表得到经常性事件也,我做到了,但我无法弄清楚如何从该查询获取事件名称,因为它们在活动表。我发现如何做到这一点没有任何例子。我试图用实例加入活动创建自定义查询,但我不知道它甚至可以查询日历表是这样的(绕过API)。

I need to do a not complicated thing, one could believe. I want to get Event instances from calendars on my phone along with titles of the events. I found several answers on Stack Overflow telling to query Instances table to get recurring events also, which I did, but I can't figure out how to get Event names from this query, because they are in Events table. I found no example of how to do this. I tried to create a custom query by joining Events with Instances, but I don't know if it's even possible to query Calendar tables like this (bypassing API).

难道有人知道如何简单地得到所有 Event.TITLE Instance.DTSTART 对于给定的起始和终止日期?

Do anybody know how to simply get all Event.TITLE, Instance.DTSTART for given start and end dates?

推荐答案

好吧,我可能需要得到一些睡眠...

Ok, I probably need to get some sleep...

实例表中有列 CalendarContract.Instances.TITLE 持有,即使它不是在实例表。查询命中一些查看不是实例表。我发誓我想这样,但没有找到标题在智能感知列。

Instances table has column CalendarContract.Instances.TITLE which holds the title even though it's not in the Instances table. The query hits some View not the Instances table. I would swear I tried this way and couldn't find TITLE in intellisense for columns.

在这里完整的解决方案的人谁可能会发现这个有用的:

Full solution here for anybody who may find this useful:

DateTime startDate = DateTime.now().withTime(0, 0, 0, 0);
DateTime endDate = startDate.plusDays(7);

Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI
            .buildUpon();
ContentUris.appendId(eventsUriBuilder, startDate.getMillis());
ContentUris.appendId(eventsUriBuilder, endDate.getMillis());

Uri eventsUri = eventsUriBuilder.build();
Cursor cursor = null;
cursor = getContentResolver().query(
        eventsUri,
        new String[] {CalendarContract.Instances.DTSTART, CalendarContract.Instances.TITLE},
        CalendarContract.Instances.DTSTART + " >= " + startDate.getMillis() + " and " + CalendarContract.Instances.DTSTART + " <= " + endDate.getMillis() + " and " + CalendarContract.Instances.VISIBLE + " = 1",
        null,
        CalendarContract.Instances.DTSTART + " ASC");

这code使用乔达时库