Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android CalendarContract重复活动,包含例外日期大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我找不到一种方法来将异常日期插入到重复发生的事件中.

上下文

我正在使用成功的事件解析.ics文件(ical格式).
这是.ics

BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:TESTinG
X-WR-TIMEZONE:Europe/Amsterdam
X-WR-CALDESC:
BEGIN:VTIMEZONE
TZID:Europe/Amsterdam
X-LIC-LOCATION:Europe/Amsterdam
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BymONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BymONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=Europe/Amsterdam:20140425T103000
DTEND;TZID=Europe/Amsterdam:20140425T113000
RRULE:FREQ=WEEKLY;BYDAY=FR
EXDATE;TZID=Europe/Amsterdam:20140516T103000
EXDATE;TZID=Europe/Amsterdam:20140502T103000
DTSTAMP:20140425T090449Z
UID:3bb37doi3qcuaih3t03ns0q9jo@google.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=TESTin
 G;X-NUM-GUESTS=0:mailto:domain.com_o300s@group.calendar.google.com
CREATED:20140425T090310Z
DESCRIPTION:
LAST-MODIFIED:20140425T090427Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMary:my-recurring-event-with-ex
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

然后,该事件将通过CalendarContract API插入到Android日历中.

dtstart:20140425T103000
dtend:20140425T113000
rrule:FREQ =每周; BYDAY = FR

问题:排除日期

如果我现在查询我的日历,我将在2014年4月25日的每个星期五看到一个活动.

问题是我还需要排除一些日期(参见ical:2014年5月2日和2014年5月16日)

尝试1

我尝试只使用EXDATE字段插入16的exdate,如下所示:
android: EXDATE format when adding a calendar event
但这没有用,并且基于Android日历源代码甚至没有使用它.

尝试2

我尝试使用CONTENT_EXCEPTION_URI插入异常
通过这样的帖子:Make exception event from original recurring event?
Google日历代码https://github.com/android/platform_packages_apps_calendar/blob/master/src/com/android/calendar/EventInfoFragment.java#L1401

ContentValues values2 = new ContentValues();

values2.put(CalendarContract.Events.ORIGINAL_INSTANCE_TIME,event.getAsString(CalendarContract.Events.DTSTART));
values2.put(CalendarContract.Events.STATUS,CalendarContract.Events.STATUS_CANCELED);

Uri.builder eventUriBuilder = CalendarContract.Events.CONTENT_EXCEPTION_URI.buildUpon();
eventUriBuilder.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER,"true");
eventUriBuilder.appendQueryParameter(CalendarContract.Calendars.account_NAME,accountName);
eventUriBuilder.appendQueryParameter(CalendarContract.Calendars.ACCount_Type,accountTypE);
ContentUris.appendId(eventUriBuilder,dbId);
Uri uriex = cr.insert(eventUriBuilder.build(),values2);

uriex总是为空.

尝试3

我尝试插入一个新事件,其中包含指向其原始事件的链接,例如在Google日历代码中,用于删除定期事件的单个条目
https://github.com/android/platform_packages_apps_calendar/blob/master/src/com/android/calendar/DeleteEventHelper.java#L361

Q

有人知道如何处理CalendarContract API中的重复事件中的异常吗?

解决方法

查询了自己的设备日历数据库.
SELEct _ID,exdate from events where exdate is not null

它包含例如exdate =“20090103T093000Z,20110101T093000Z”
所以日期必须格式化为utc(“Z”)

> and based on the android calendar source code it (the field exdatE) 
> is not event used.

当你从事件中计算/更新(事件 – )实例时,你有没有分析后启动事件?

大佬总结

以上是大佬教程为你收集整理的Android CalendarContract重复活动,包含例外日期全部内容,希望文章能够帮你解决Android CalendarContract重复活动,包含例外日期所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。