我正在尝试使用Android的新日历API来读取今天所有的日历事件。我很难在数据库查询上找到正确的选择来返回所有事件。似乎所有重复发生的和全天的事件都被排除在选择之外。什么样的选择参数允许我从日历api中获得今天的所有事件?
这是我目前的尝试:
Cursor cur = null;
String selection = "((" + CalendarContract.Events.DTSTART
+ " >= ?) AND (" + CalendarContract.Events.DTEND + " <= ?))";
Time t = new Time();
t.setToNow();
String dtStart = Long.toString(t.toMillis(false));
t.set(59, 59, 23, t.monthDay, t.month, t.year);
String dtEnd = Long.toString(t.toMillis(false));
String[] selectionArgs = new String[] { dtStart, dtEnd };
cur = c.getContentResolver().query(CalendarContract.Events.CONTENT_URI,
null, selection, selectionArgs, null);我不确定如何扩大选择范围或增加选择范围,以获得重复发生的事件和全天事件。任何帮助都将不胜感激。
发布于 2012-09-10 00:34:12
你的条件只给你今天严格限制的事件。你应该检查今天之前开始和之后结束的那些(多天事件)。
对于重复发生的事件,我会手动检查它们。我找不到别的办法。
我使用类似这样的东西:
String selection = "((" + CalendarContract.Events.DTSTART + " <= ?) AND (" + CalendarContract.Events.DTEND + " >= ?)) OR (" + CalendarContract.Events.RRULE + " is not null )";
String[] selectionArgs = new String[] { dtEnd, dtStart};致以敬意,
https://stackoverflow.com/questions/10133616
复制相似问题