如何删除日历条目?
问题描述:
我想实现我的第一个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);
根据我的插入方法访问日历工作。
谢谢,亚瑟!
答
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
现在我的日历是空的:-)
答
从用户日历中删除东西的正确方法是使用适当的GData API并从Google日历中删除它。操作日历应用程序的内容提供者 - 就像您正在尝试执行的操作)不是公共API的一部分。
我也读过它。我想实现类似于这个问题中描述的东西:http://*.com/questions/846942/is-there-a-way-to-access-the-calendars-entries-without-using-gdata-java-client – Arthur 2009-09-24 15:28:44