You missed calendars
when you try to execute this line
Cursor cursor = getContentResolver().query(
Uri.parse(getCalendarUriBase(this)), /* <-- unknown URL content */
new String[] { "calendar_id", "displayname" },
null,null,null);
resulting in IllegalArgumentException
.
Just add the calendars
after getCalendarUriBase(this)
.
Cursor cursor = getContentResolver().query(
Uri.parse(getCalendarUriBase(this)+"calendars"),
new String[] { "_id", "displayName" },
null,null,null);
Note:
- Use
_id
to get the calendar ID if you query fromcalendars
table.calendar_id
is defined as a foreign key in other tables (e.g.events
).- Use
displayName
for GingerBread or below. For Ice Cream Sandwich and above, usecalendar_displayName
.
When adding an event, you need to include: calendar ID, start date, end date (or recurrence rule), and event timezone. You have included all but the timezone. Try adding
values.put("eventTimezone", TimeZone.getDefault().getID());
before inserting the event.