通过 events.dtend 更新日历实例



当我更新 CalendarContract.Events DTEND 列时,为什么更改没有显示在 CalendarContract.Instances END 列中?

我的应用允许用户使用 CalendarContract.Events API 查看和更改日历事件。 该代码对"事件"表执行更新,然后使用"实例"表将其读回(稍后)。 例如,对 TITLE 的更改工作正常(也就是说,我更新事件并可以读回实例中的更改)。 对 Events.DTEND 所做的更改确实显示在 Instances.DTEND 中,但是我怎样才能让该更新也显示在 Instances.END 中?

这很重要,因为显然,Android 日历应用程序(以及我的应用程序)使用 Instances.BEGIN 和 Instances.END 来确定要在日历中显示的内容。

这是我的更新代码:

  ContentResolver cr = getContentResolver();
  ContentValues values = new ContentValues();
  values.put (Events.CALENDAR_ID, calendarId);
  values.put (Events.TITLE, title);
  values.put (Events.DTEND, eventEnd.getTimeInMillis());
  String where = "_id =" + eventId +
                 " and " + CALENDAR_ID + "=" + calendarId;
  int count = cr.update (Events.CONTENT_URI, values, where, null);
  if (count != 1)
     throw new IllegalStateException ("more than one row updated");

谢谢。

解决方案原来是添加开始日期:

  ContentResolver cr = getContentResolver();
  ContentValues values = new ContentValues();
  values.put (Events.CALENDAR_ID, calendarId);
  values.put (Events.TITLE, title);
  values.put (Events.DTSTART, eventStart.getTimeInMillis());
  values.put (Events.DTEND, eventEnd.getTimeInMillis());
  String where = "_id =" + eventId +
                 " and " + CALENDAR_ID + "=" + calendarId;
  int count = cr.update (Events.CONTENT_URI, values, where, null);
  if (count != 1)
     throw new IllegalStateException ("more than one row updated");

请注意:这种情况仅显示如何更新非重复性事件。 非定期事件具有空 RRULE。

我怀疑提供程序代码所做的是仅使用您提供的值,而不是重新获取开始日期本身(显然,如果用户更改开始日期,您无论如何都必须提供它)。 从减少数据库访问的角度来看,这是有道理的。 太糟糕了,谷歌没有记录任何这些。

最新更新