我遇到了以事件方式向Google日曆添加事件的問題。Android日曆創建遞歸類型
這裏是代碼:
private void addToGoogleCalendar(long beginTime) {
ContentValues event = new ContentValues();
Observable.from(dataKeeper.getCalendarIds().keySet()).filter(key -> dataKeeper.getCalendarIds().get(key).equals(defaultCalendarName.getText().toString())).forEach(key ->
event.put(CalendarContract.Reminders.CALENDAR_ID, Integer.parseInt(key))
);
event.put(CalendarContract.Reminders.TITLE, reminderName.getText().toString());
if (!TextUtils.isEmpty(commentEdittext.getText().toString()))
event.put(CalendarContract.Reminders.DESCRIPTION, commentEdittext.getText().toString());
event.put(CalendarContract.Reminders.EVENT_TIMEZONE, TimeZone.getDefault().getID());
event.put(CalendarContract.Reminders.DTSTART, beginTime);
event.put(CalendarContract.Reminders.DTEND, dataKeeper.getEnd());
event.put(CalendarContract.Reminders.EVENT_COLOR, getResources().getColor(R.color.primary));
// http://tools.ietf.org/html/rfc2445
if (dataKeeper.getPeriod() > 0 && dataKeeper.getPeriod() != 7)
event.put(CalendarContract.Reminders.RRULE, String.format("FREQ=DAILY;INTERVAL=%d;UNTIL=%s", dataKeeper.getPeriod() - 1,
new SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(dataKeeper.getEnd())));
else if (dataKeeper.getPeriod() == 7)
event.put(CalendarContract.Reminders.RRULE, String.format("FREQ=WEEKLY;INTERVAL=1;UNTIL=%s",
new SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(dataKeeper.getEnd())));
event.put(CalendarContract.Reminders.ALL_DAY, 1); // 0 for false, 1 for true
event.put(CalendarContract.Reminders.STATUS, CalendarContract.Events.STATUS_CONFIRMED);
String eventUriString = "content://com.android.calendar/events";
getContentResolver().insert(Uri.parse(eventUriString), event);
}
Inrerval = 1
所以,當我添加事件,它增加的需求,但在幾秒鐘內我看到的事件增加了遞歸。第一天一次,第二天兩次等等。
只調用方法,所以我不知道WTF發生。