我正在开发一个应用程序,它从calendar.ics
文件中读取所有事件,然后显示所有事件。我的代码可以很好地处理单个事件,并且我能够从文件中提取所有事件,因为它包含所有事件。
但是,当我创建重复事件时,我无法获取除第一个事件之外的所有事件,因为 calendar.ics
文件包含 "RRULE"
而不是所有事件。
我已经尝试过 "rfc2445.jar"
但它不起作用,或者也许我不知道如何使用它......
是否有任何库/代码/方法/函数可以帮助我解析和显示所有事件?
CalendarBuilder builder = new CalendarBuilder();
Calendar calendar = null;
calendar = builder.build(file);
Log.d("RRULE 1: ", component.getProperty("RRULE").getName());
Log.d("RRULE 2: ", component.getProperty("RRULE").getValue());
Log.d("RRULE 3: DTSTART: ",component.getProperty("DTSTART").getValue());
Log.d("RRULE 4: DTEND: ", component.getProperty("DTEND").getValue());
.......
上面是我的代码 fragment ,我得到了以下结果
D/RRULE 1:: RRULE
D/RRULE 2:: FREQ=DAILY;COUNT=184
D/RRULE 3: DTSTART:: 20160701T170000
D/RRULE 4: DTEND:: 20160701T200000
我不知道如何解析 FREQ 中的所有事件?
最佳答案
您可以使用我们的库lib-recur .
(非常)基本的用法(不考虑时区)如下:
RecurrenceRule rule = new RecurrenceRule(component.getProperty("RRULE").getValue());
DateTime start = DateTime.parse(component.getProperty("DTSTART").getValue());
int maxInstances = 100; // limit instances for rules that recur forever
RecurrenceRuleIterator it = rule.iterator(start);
while (it.hasNext() && (!rule.isInfinite() || maxInstances-- > 0))
{
DateTime nextInstance = it.nextDateTime();
// do something with nextInstance
}
该库还支持多个 RRULE
、EXRULE
、EXDATE
、RDATE
和时区。
关于java - 如何从 Android 中的 RRULE 的 ics 文件中列出/提取所有重复事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41763246/