Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, calendar, adding RRULE to event never works

I'm following rfc2445 spec and insert a recurrent event to cal, but always get invalid recurrence error.

Invalid recurrence rule: RRULE:FREQ=WEEKLY;UNTIL=20141007T000000Z;WKST=SU;BYDAY=TU,TH

This is my code, note I return the above constant rrule string to make sure I don't violate the specs, I just change the year from 1997 to 2014. Any idea why it doesn't work? thanks

ContentResolver cr = getContentResolver();
        ContentValues values = new ContentValues();
        values.put(CalendarContract.Events.DTSTART, model.getStartTime().toMillis(false));
        values.put(CalendarContract.Events.DTEND, model.getEndTime().toMillis(false));
        values.put(CalendarContract.Events.EVENT_TIMEZONE, timezone);
        values.put(CalendarContract.Events.TITLE, model.getTitle());
        values.put(CalendarContract.Events.EVENT_LOCATION, model.getLocation().getName());
        values.put(CalendarContract.Events.DESCRIPTION, model.getDescription());
        values.put(CalendarContract.Events.CALENDAR_ID, calId);
        String recurString ="RRULE:FREQ=WEEKLY;UNTIL=20141007T000000Z;WKST=SU;BYDAY=TU,TH"
        
        values.put(CalendarContract.Events.RRULE, recurString);
        
       
        Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
like image 267
EyeQ Tech Avatar asked Dec 25 '22 08:12

EyeQ Tech


2 Answers

I figured it out, the RRULE string shouldn't contain the word 'RRULE' itself.

like image 170
EyeQ Tech Avatar answered Jan 11 '23 00:01

EyeQ Tech


If you are using Android standard CalendarContract, please use DURATION field instead of DTEND, otherwise, your events won't recurring.

Refer to the following link: http://developer.android.com/reference/android/provider/CalendarContract.Events.html

  • dtend if the event is non-recurring
  • duration if the event is recurring
  • rrule or rdate if the event is recurring
like image 23
LabLu Avatar answered Jan 10 '23 22:01

LabLu