In my app I use two calendars, lets say calendar "business" with CalendarContract.Events.CALENDAR_ID = 1
, and calendar "privat" with CalendarContract.Events.CALENDAR_ID = 2
.
If the user chooses to see the events of both calendars in my app, I somehow need to get the events of both calendars into a cursor.
I have tried it like in the following code, where I put into my selection both calendarIds with an OR
, but that shows me an incredible number of events.
So my question is, how to get a cursor with events of two calendars?
String[] projection = { CalendarContract.Events._ID,
CalendarContract.Events.CALENDAR_ID,
CalendarContract.Events.TITLE,
CalendarContract.Events.DESCRIPTION,
CalendarContract.Events.DTSTART, CalendarContract.Events.DTEND,
CalendarContract.Events.DURATION,
CalendarContract.Events.DELETED };
SelectionArgs = new String[] { strCalendarStart,
strCalendarStop, "0",
intPrivateCalendarId.toString(),
intBeruflicheCalendarId.toString() };
selection = "((" + CalendarContract.Events.DTSTART + " >= ?) AND ("
+ CalendarContract.Events.DTEND + " <= ?)AND " + "("
+ CalendarContract.Events.DELETED + " = ?) AND"
+ "(" + CalendarContract.Events.CALENDAR_ID
+ " = ?) OR" + "("
+ CalendarContract.Events.CALENDAR_ID + " = ?))";
Cursor curCalendar = cr.query( CalendarContract.Events.CONTENT_URI,
projection, selection, SelectionArgs,
CalendarContract.Events.DTSTART + " ASC" );