gpt4 book ai didi

android - WearableCalendarContract 查询不返回重复事件

转载 作者:行者123 更新时间:2023-11-29 15:51:46 24 4
gpt4 key购买 nike

我正在为 Android Wear 创建一个表盘,它将显示日历事件。基于this page (以及 SDK 中提供的 WatchFace 示例),我设法查询了当天的下一个事件,并将它们显示在我的表盘上(下面是我用来查询事件的代码)。

问题是重复发生的事件不会在光标中返回,因此不会显示在表盘上。是否有任何参数可以添加到查询中以获取重复发生的事件?

private static final String[] PROJECTION = {
CalendarContract.Calendars._ID, // 0
CalendarContract.Events.DTSTART, // 1
CalendarContract.Events.DTEND, // 2
CalendarContract.Events.DISPLAY_COLOR, // 3
};

protected List<SpiralEvent> queryEvents() {
// event is a custom POJO object
List<Event> events = new ArrayList<>();

long begin = System.currentTimeMillis();

Uri.Builder builder = WearableCalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, begin);
ContentUris.appendId(builder, begin + DateUtils.DAY_IN_MILLIS);

final Cursor cursor = mService.getContentResolver()
.query(builder.build(),
PROJECTION,
null, // selection (all)
null, // selection args
null); // order

// get the start and end time, and the color
while (cursor.moveToNext()) {
long start = cursor.getLong(1);
long end = cursor.getLong(2);
int color = cursor.getInt(3);
events.add(new Event(start, end, color));
}

cursor.close();

return events;
}

最佳答案

您必须使用 CalendarContract.Instances.BEGIN 而不是 CalendarContract.Events.DTSTART;因此,您可以将 PROJECTION 更改为:

private static final String[] PROJECTION = {
CalendarContract.Calendars._ID, // 0
CalendarContract.Events.BEGIN, // 1
CalendarContract.Events.END, // 2
CalendarContract.Events.DISPLAY_COLOR, // 3
};

原因是:

  • Events.DTSTART 返回原始创建事件的开始时间。请注意,此事件通常是过去的事情;因此,它被过滤掉了。
  • Events.BEGIN 返回每个事件实例的开始时间。

CalendarEvent.java 中查看源代码来 self 的 github 示例项目 https://github.com/mtrung/android-WatchFace .

关于android - WearableCalendarContract 查询不返回重复事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29565075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com