我正在使用Android日历。如何使用代码删除日历事件?有可能吗?
为了澄清,我想提一下,我不想要同步过程或想要使用gdata api删除事件。
我只想删除本地日历活动。
答案 0 :(得分:3)
尝试使用事件ID的Uri删除事件。
Uri uri='URI OF THE EVENT';
getContentResolver().delete(uri, null, null);
答案 1 :(得分:3)
简短的方法:
Uri eventUri = Uri.parse("content://calendar/events"); // or "content://com.android.calendar/events"
Cursor cursor = contentResolver.query(eventUri, new String[]{"_id"}, "calendar_id = " + calendarId, null, null); // calendar_id can change in new versions
while(cursor.moveToNext()) {
Uri deleteUri = ContentUris.withAppendedId(eventUri, cursor.getInt(0));
contentResolver.delete(deleteUri, null, null);
}
答案 2 :(得分:2)
没有“删除本地日历的事件”这样的概念:
答案 3 :(得分:1)
虽然它不是SDK的一部分,但您可以访问它,但访问它需要您自担风险,因为它不受支持。我遵循的一个很好的教程是这些链接:
http://www.developer.com/ws/article.php/3850276/Working-with-the-Android-Calendar.htm (死链接)
http://jimblackler.net/blog/?p=151&cpage=2#comments
http://android-codes-examples.blogspot.com/2011/02/insertion-and-deletion-of-calendar.html
http://hanscappelle.blogspot.com/2011/03/android-calendar-api-glitches.html
一些好的示例代码:http://pastebin.com/jpnqTp1n