I am trying to delete all calendar entries from calendar, but this code didn’t delete no entry.
Source code:
ContentResolver cr = getContentResolver();
Uri CALENDAR_URI = Uri.parse("content://com.android.calendar/events");
int id = 2; // calendar ID
Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);
cr.delete(uri, null, null);
First off, your code is bound to break since the Calendar API is not public. In fact, the content provider changed between Android 2.1 and 2.2, so your app will not work on all phones.
That said, I noticed that a blanket delete on calendar entries doesn’t work. You first need to do a query to get a list, and then delete them individually.
Note that if you delete too many, the Android sync will act up. There might be a notification saying that too many entries have been deleted, and it may take a long time for your request (hours) to be processed.