【问题标题】:Update calendar instances.end via events.dtend通过 events.dtend 更新日历 instances.end
【发布时间】:2012-11-16 13:48:19
【问题描述】:

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

我的应用允许用户使用 CalendarContract.Events API 查看和更改日历事件。该代码对 Events 表执行更新,然后使用 Instances 表将其读回(稍后)。例如,对 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");

谢谢。

【问题讨论】:

    标签: android events calendar updates instances


    【解决方案1】:

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

      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 为空。

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

    【讨论】:

      猜你喜欢
      • 2013-10-04
      • 1970-01-01
      • 2020-09-16
      • 2020-10-18
      • 1970-01-01
      • 2015-03-02
      • 2019-12-18
      • 1970-01-01
      • 2017-09-14
      相关资源
      最近更新 更多