0

I am using the following code to insert event to calender

  public void setRemindar(String calenderDate, String endcalenderDate,
              int customHour, int customMin, int endcustomHour, int endcustomMin,
              String title) {

          Uri EVENTS_URI = Uri
                 .parse(getCalendarUriBase(getActivity()) + "events");
             ContentResolver cr = context.getContentResolver();

         TimeZone timeZone = TimeZone.getDefault();
         Calendar cal = Calendar.getInstance();
         try {
              eventDate = new SimpleDateFormat("MM/dd/yyyy").parse(calenderDate);
              endEventDate = new SimpleDateFormat("MM/dd/yyyy")
                      .parse(endcalenderDate);

              cal.setTime(eventDate);
              cal.set(Calendar.HOUR_OF_DAY, customHour);
              cal.set(Calendar.MINUTE, customMin);
              startCalTime = cal.getTimeInMillis();

              cal.setTime(endEventDate);
              cal.set(Calendar.HOUR_OF_DAY, endcustomHour);
              cal.set(Calendar.MINUTE, endcustomMin);
              endCalTime = cal.getTimeInMillis();

             // event insert
                ContentValues values = new ContentValues();
                values.put("calendar_id", 1);
                values.put(CalendarContract.Events.TITLE, title);
                values.put(CalendarContract.Events.DESCRIPTION, dateToPass);
               values.put(CalendarContract.Events.EVENT_LOCATION, location);
               values.put(CalendarContract.Events.DTSTART, startCalTime);
               values.put(CalendarContract.Events.DTEND, endCalTime);
               values.put(CalendarContract.Events.STATUS, 1);
              values.put(CalendarContract.Events.HAS_ALARM, 1);
              values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());

              Uri event = cr.insert(EVENTS_URI, values);
              // reminder insert
               Uri REMINDERS_URI = Uri.parse(getCalendarUriBase(getActivity())
                     + "reminders");
              values = new ContentValues();
              values.put("event_id", Long.parseLong(event.getLastPathSegment()));
              values.put("method", 1);
              values.put("minutes", 5);
              cr.insert(REMINDERS_URI, values);
          } catch (Exception e) {
              // TODO: handle exception
                 }
      }

and it inserter successfully in the calender but the problem is that its not repeating . What I want is that suppose event start-date is 13 Sep 2014 and event end-date is 17 Sep 2014 then its show the events between these two date . Right now i am only able to set event to 13 Sep 2014. when I click on 13 Sep 2014 in calender its shows me the event entry but when i click on 14 Sep its showing me nothing. it has to show entry between 13 Sep to 17 Sep 2014 . Please help me to achieve the following

Nirmal
  • 939
  • 10
  • 24

1 Answers1

0

You need to specify RRule (recurrence rule) defining the type of recurrence while inserting it to the calendar database. This code works for me:

values.put(Events.RRULE, "FREQ=" + recurrence + ";UNTIL="
                    + "This is timestamp value");

Here recurrence is either DAILY, WEEKLY, MONTHLY or YEARLY all capital letters. If this doesn't work then let me know.

Illegal Argument
  • 10,090
  • 2
  • 44
  • 61