我正在使用以下代码来更新我的重复事件。
ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();
TimeZone timeZone = TimeZone.getDefault();
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
beginTime.setTime(myEvent.START_DATE);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
endTime.setTime(myEvent.END_DATE);
endMillis = endTime.getTimeInMillis();
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
values.put(CalendarContract.Events.TITLE,myEvent.TITLE);
values.put(CalendarContract.Events.AVAILABILITY,myEvent.AVAILABILITY);
values.put(CalendarContract.Events.ACCESS_LEVEL,myEvent.ACCESS_LEVEL);
values.put(CalendarContract.Events.EVENT_LOCATION,myEvent.EVENT_LOCATION);
values.put(CalendarContract.Events.ALL_DAY,myEvent.ALL_DAY);
values.put(CalendarContract.Events.GUESTS_CAN_INVITE_OTHERS,myEvent.GUESTS_CAN_INVITE_OTHERS);
values.put(CalendarContract.Events.GUESTS_CAN_MODIFY,myEvent.GUESTS_CAN_MODIFY);
values.put(CalendarContract.Events.GUESTS_CAN_SEE_GUESTS,myEvent.GUESTS_CAN_SEE_GUESTS);
values.put(CalendarContract.Events.DESCRIPTION, myEvent.Note);
values.put(CalendarContract.Events.CALENDAR_ID, myEvent.ID);
if(myEvent.RRULE != null && myEvent.RRULE.length()>0)
{
values.put(CalendarContract.Events.RRULE,myEvent.RRULE);
long duration = Math.max(0,endMillis- startMillis);
if(duration > 0)
values.put(CalendarContract.Events.DURATION, endMillis);
if(myEvent.EXDATE != null && myEvent.EXDATE.length()>0)
{
values.put(CalendarContract.Events.EXDATE,myEvent.EXDATE);
}
}
else
{
values.put(CalendarContract.Events.DTEND, endMillis);
}
Uri updateUri = ContentUris.withAppendedId(Events.CONTENT_URI, myEvent.EVENT_ID);
rowUpdated= cr.update(updateUri, values, null, null);
我添加了一个例外日期。之后,当我下次读取事件时,事件 RRULE 变为空。事件的所有实例都消失了。由于没有足够的文档来查找信息,因此很难对重复事件进行编程。请帮忙!