2011-04-26 172 views
0

我想從日曆中刪除所有日曆條目,但此代碼並未刪除沒有條目。刪除日曆中的所有條目

的源代碼:

ContentResolver cr = getContentResolver(); 
         Uri CALENDAR_URI = Uri.parse("content://com.android.calendar/events"); 
         int id = 2; // calendar ID 
         Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id); 
         cr.delete(uri, null, null); 

回答

1

首先,你的代碼勢必打破,因爲日曆API是不公開的。實際上,內容提供商在Android 2.1和2.2之間進行了更改,因此您的應用無法在所有手機上使用。

這就是說,我注意到在日曆條目上的全部刪除不起作用。首先需要執行查詢以獲取列表,然後單獨刪除它們。

請注意,如果刪除太多,Android同步將會起作用。可能會有一個通知說,有太多的條目已被刪除,並且處理您的請求(小時)可能需要很長時間。

+0

我試過這段代碼:Uri eventsUri = Uri.parse(「content://com.android.calendar/events」); \t \t \t \t Uri eventUri = ContentUris.withAppendedId(eventsUri,2); (eventUri,null,null);但我不知道這個「2」是日曆的id還是條目的id ContentUris.withAppendedId(eventsUri,>> 2 <<);我不知道這個「2」是否是日曆的ID或條目ContentUris.withAppendedId(eventsUri,>> 2 <<);我不知道這個「2」 – Husky 2011-04-26 18:47:52

+0

事件條目的ID。您查詢事件,然後使用事件ID上的withAppendedId對每個事件調用delete。 – EboMike 2011-04-26 19:31:23