将DATE添加到日历重复活动

时间:2014-01-16 20:09:17

标签: android-calendar recurring-events

我使用以下代码更新我的定期活动。

            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变为null。事件的所有实例都消失了。由于没有足够的文件来查找信息,因此很难对周期性事件进行编程。 请帮忙!

0 个答案:

没有答案