2012-11-28 47 views
4

當我更新CalendarContract.Events DTEND列時,爲什麼更改不顯示在CalendarContract.Instances END列中?更新日曆instances.end via events.dtend

我的應用程序允許用戶使用CalendarContract.Events API查看和更改日曆事件。代碼對Events表執行更新,然後使用Instances表將其讀回(稍後)。例如,對TITLE的更改可以正常工作(即,我更新了事件並可以讀回實例中的更改)。 Events.DEND中的更改顯示在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"); 

感謝。

回答

2

該解決方案可謂是添加起始日期:

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。

我懷疑提供程序代碼的做法是僅使用您提供的值而不是重新開始日期本身(顯然,如果用戶更改開始日期,您將不得不提供它)。從減少數據庫訪問的角度來看,這是有意義的。太糟糕谷歌沒有記錄任何這一點。