2009-09-24 57 views
2

我想實現我的第一個android程序。它應該寫日曆條目(我知道,開始編程Andorid不是最好的任務)。如何刪除日曆條目?

我已經試過:

Uri CALENDAR_URI = Uri.parse("content://calendar/events"); 
ContentResolver cr = getContentResolver(); 
cr.delete(CALENDAR_URI, null, null); // Delete all 
cr.delete(CALENDAR_URI, "calendar_id=1", null); // Delete all in default calendar 
cr.delete(CALENDAR_URI, "_id=1", null); // Delete specific entry 

毫無效果。我將取消「無法刪除該URL」。

插入一個日曆項很簡單:

ContentValues values = new ContentValues(); 
values.put("calendar_id", 1); 
values.put("title", this.title); 
values.put("allDay", this.allDay); 
values.put("dtstart", this.dtstart.toMillis(false)); 
values.put("dtend", this.dtend.toMillis(false)); 
values.put("description", this.description); 
values.put("eventLocation", this.eventLocation); 
values.put("visibility", this.visibility); 
values.put("hasAlarm", this.hasAlarm); 

cr.insert(CALENDAR_URI, values); 

根據我的插入方法訪問日曆工作。

謝謝,亞瑟!

回答

8

OK,有一件事我沒有嘗試:

Uri CALENDAR_URI = Uri.parse("content://calendar/events"); 
int id = 1; // calendar entry ID 
Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id); 
cr.delete(uri, null, null); 

這就是我失蹤:

Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id); 

應導致內容://日曆/事件/ 1

現在我的日曆是空的:-)

1

從用戶日曆中刪除東西的正確方法是使用適當的GData API並從Google日曆中刪除它。操作日曆應用程序的內容提供者 - 就像您正在嘗試執行的操作)不是公共API的一部分。

+0

我也讀過它。我想實現類似於這個問題中描述的東西:http://stackoverflow.com/questions/846942/is-there-a-way-to-access-the-calendars-entries-without-using-gdata-java-client – Arthur 2009-09-24 15:28:44