Is it possible to remove the Android calendar event

回眸只為那壹抹淺笑 提交于 2019-12-31 07:27:06

问题


I am using the Android calendar. How can I remove a calendar event using code? Is it possible?

For clarification, I would like to mention that I don't want a sync process or want to remove events using gdata api.

I only want to remove a local calendar event.


回答1:


There is no such concept as "remove local calendar's event":

  • There is no "local calendar". There is, at most, a cached representation of the user's Google Calendars.
  • The Calendar application is not part of the SDK



回答2:


Try this to delete the event using Uri of the event id.

Uri uri='URI OF THE EVENT';
getContentResolver().delete(uri, null, null);



回答3:


A short way:

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);
}



回答4:


Though it is not part of the SDK you can access it, but access it at your own risk since it is not supported. A good tutorial that I followed are these links:

http://www.developer.com/ws/article.php/3850276/Working-with-the-Android-Calendar.htm (dead link)

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

some good sample code: http://pastebin.com/jpnqTp1n



来源:https://stackoverflow.com/questions/2742778/is-it-possible-to-remove-the-android-calendar-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!