WearableCalendarContract查询不会返回重复事件 [英] WearableCalendarContract query doesn't return recurring events
问题描述
我正在为Android Wear创建一个表面,该表面将显示日历事件.基于此页面(以及SDK),我设法查询了当天的下一个事件,并将它们显示在我的表面上(下面是我用来查询事件的代码).
I'm creating a watchface for Android Wear which will display calendar events. Based on this page (and the WatchFace
sample provided in the SDK), I managed to query the next events for the day, and display them on my watchface (below is the code I use to query the events).
问题在于重复发生的事件不会在游标中返回,因此不会显示在表盘上.查询中是否要添加任何参数以获取重复事件?
The problem is that recurring events are not returned in the cursor, and thus are not displayed on the watch face. Is there any parameter to add in the query to get recurring events ?
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
更改为:
You have to use CalendarContract.Instances.BEGIN
instead of CalendarContract.Events.DTSTART
; thus, you can change the PROJECTION
to:
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
返回事件的每个实例的开始时间.
Events.DTSTART
returns start time of the original created event. Note that this event is often in the past; thus, it's filtered out.Events.BEGIN
returns start time of each instance of the event.
在 https中的calendar/CalendarEvent.java"rel =" nofollow> CalendarEvent.java ://github.com/mtrung/android-WatchFace .
Check out source in CalendarEvent.java from my github sample project https://github.com/mtrung/android-WatchFace.
这篇关于WearableCalendarContract查询不会返回重复事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!