I have an application which uses the Calendar Provider for adding, editing and removing events. I have an interface of a calendar, which shows which days have events attached. Adding events works Perfectly. For adding an event I hardcoded the calendarID with the number 3, so calID = 3.
long calID=3;
values.put(Events.DESCRIPTION, description);
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "Europe/London");
Uri uri = cr.insert(Events.CONTENT_URI, values);
This works perfectly. the View i've programmed shows the events. I open the Calendar application which comes included on my phone (Xperia J) and I can see that the event is there.
I tried to delete events with the following code:
ContentResolver cr = mContext.getContentResolver();
ContentValues values = new ContentValues();
Uri deleteUri = null;
deleteUri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
int rows = mContext.getContentResolver().delete(deleteUri, null, null);
This code was DIRECTLY copied from developer.android.com website.
This doesn't Delete! I debugged the code and the value of 'rows' is equal to 1, so effectivelly the row should have been deleted.
However I get back to my app, and the event still exists there. Interesting thing: I've checked the Calendar Application that comes in my phone, and the event doesn't exist there. So it has been deleted (?). I thought that maybe i am not refreshing my app, so i closed it, reinstalled it, and it never deletes. I debug again the code for deletion, and once again the 'rows' value is equal to one, to the very same event! So, 'rows' is always returning 1 EVERY TIME i want to the delete it. So the row was deleted, but it was not deleted.
What is happening here? Is it because when I added the event, I hardcoded the calendarID?