我想要做的只是刪除我在日曆中保存的內容,而不是我已經在日曆中顯示的所有內容..爲此,我使用以下代碼。但它會刪除calendar..so的所有內容誰能告訴我怎麼能防止..如何刪除日曆中的特定事件
Uri CALENDAR_URI = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver();
cr.delete(CALENDAR_URI, null, null); // Delete all
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);
所以我想是隻刪除由我把那進入......
刪除事件
Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");
ContentResolver cr = c.getContentResolver();
deleteEvent(cr, EVENTS_URI, 1);
private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId) {
Cursor cursor;
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + calendarId, null, null);
while(cursor.moveToNext()) {
long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
}
cursor.close();
}
這將只工作,如果有安裝在手機上的默認日曆應用程序。 – st0le
請使用Google日曆GData API操作用戶的Google日曆。 – CommonsWare
@Andr你好我正面臨同樣的問題,你是如何解決這個問題的?任何建議將是非常有用的幫助我們... –