How to add event in Android calendar, repeated eve

2019-05-21 05:36发布

问题:

I want to add an event to the Android calendar using this code:

cr = getContentResolver();
ContentValues values = new ContentValues();
values.put(Events.DTSTART, startMillis);
values.put(Events.DURATION, "P3600S");
values.put(Events.TITLE, "MyTestNew");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "India");
values.put(Events.ALL_DAY, 1);
values.put(Events.RRULE, "FREQ=WEEKLY;WKST=SU;BYDAY=SA");
uri = cr.insert(Events.CONTENT_URI, values);

But I want to add this event which should repeat every three days than what will be changed in my (Events.RRULE, parameter. How might I do this?

回答1:

finally I found the solution.

values.put(Events.DTSTART, startMillis);
values.put(Events.DURATION, "P1800S");
values.put(Events.TITLE, "MyTestNew");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "India");
values.put(Events.RRULE, "FREQ=DAILY;INTERVAL=3");
uri = cr.insert(Events.CONTENT_URI, values);


回答2:

This code start the default calender of android and you can add event on it.

String dtStart = "2012" + "" + "06-11-01T10:50:00Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {Date date = format.parse(dtStart);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
//cal.setTime(date);

Intent intent = new Intent(Intent.ACTION_EDIT);                                        intent.setType("vnd.android.cursor.item/event");                     
intent.putExtra("beginTime", cal.getTimeInMillis());                            
intent.putExtra("allDay", false);                           
intent.putExtra("rrule", "FREQ=DAILY;COUNT=1");                         
intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000);                     
intent.putExtra("title", "Booking Confirm Notification");                           
intent.putExtra("Description", "Please check details");                         
startActivity(intent);


Arun chandravanshi
Thanks.