I've been playing around with the Android Calendar Provider to create local (non-synced) calendars but I finally ended up with calendars with null
getContentResolver().query(CalendarContract.Calendars.CONTENT_URI, null, CalendarContract.Calendars.ACCOUNT_TYPE + " IS NULL", null, null);
getContentResolver().delete(CalendarContract.Calendars.CONTENT_URI, CalendarContract.Calendars.ACCOUNT_TYPE + " IS NULL", null);
java.lang.IllegalArgumentException: the name must not be empty: null
Here is what happens (note all links point to the 5.1.1 CalendarProvider, but it's probably safe to assume that it works the same in Android 6):
modifyCalendarSubscriptionis called for every calendar to remove (no matter how you selected them).
modifyCalendarSubscriptionthe provider reads the ACCOUNT_NAME and ACCOUNT_TYPE column for each of these calendars and tries to create an
null, it crashes in the
Accountconstructor when it checks for
nullvalues. That's where the eException you see is actually thrown.
So, not matter how you delete the calendar, it will always fail at the
Account constructor because the account name in the database is empty.
I didn't check it yet, but you might be able to override account name and type with an update operation. So try to set it to something that's not
If that doesn't work you either need root access to remove the calendar manually or you go to
All apps ->
Calendar storage and clear the entire calendar database (
ACCOUNT_TYPE columns will only work if you manage to match the conditions to pass this line: CalendarProvider2.java, line 3989 given that line and the conditions to get there still exists in Android 6.
It think it should work if you don't append the calendar id to the
Uri and you don't select the calendar by their id. So making your
update and resetting
ACCOUNT_TYPE to something that's not
null should do the trick.