I have followed the tutorial in this link - http://jimblackler.net/blog/?p=151&cpage=2#comment-52767 to access the internal android calendar database (even though it is
Use the Instances
table if you need to locate recurring events.
The URIs for querying it are:
instances/when/*/*
- All instances between two times (milliseconds)instances/whenbyday/*/*
- All instances between two times (days)instances/groupbyday/*/*
- Same as whenbyday
, but grouped by the start dayThe list of columns in that table are:
_id
- The ID of this instanceevent_id
- The event it was created frombegin
- Begin time (milliseconds)end
- End time (milliseconds)startDay
- Start day of instanceendDay
- End day of instancestartMinute
- Minutes since midnight (0..1440)endMinute
- Minutes since midnightYou can also use the columns from the Events
and Calendar
tables.
You can see an example on the same page that you linked: http://jimblackler.net/blog/?p=151
Example:
String[] projection = new String[] {
"title", "description", "begin", "eventLocation"
};
String selection = "calendar_id = " + calID;
String path = "instances/when/" + (now - window) + "/" + (now + window);
String sortOrder = "begin DESC";
Cursor managedCursor = getCalendarManagedCursor(
projection, selection, path, sortorder);
Edit: It seems Google got around to document the Calendar Provider. Browse to Calendar Providier | Google Developers for more information.
I finally made this work in the following way. Remember DTSTART, DTEND, _ID don't work for Instances table even if you can access them. Use BEGIN, END and Event_ID instead. Please refer to these 2 links: How to get calendar events with title including recurring events and Android Calendar Recurring Events Have Wrong End Date/Time
long now = System.currentTimeMillis();
Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(eventsUriBuilder, Long.MIN_VALUE);
ContentUris.appendId(eventsUriBuilder, Long.MAX_VALUE);
Uri eventsUri = eventsUriBuilder.build();
Cursor cursor = context.getContentResolver().query(
eventsUri,
new String[] {CalendarContract.Instances.CALENDAR_ID, CalendarContract.Instances.TITLE,
CalendarContract.Instances.DESCRIPTION, CalendarContract.Instances.BEGIN,
CalendarContract.Instances.END, CalendarContract.Instances.EVENT_LOCATION,
CalendarContract.Instances.EVENT_ID},
CalendarContract.Instances.BEGIN + " >= " + now + " and " + CalendarContract.Instances.BEGIN
+ " <= " + (now + 2592000000L) + " and " + CalendarContract.Instances.VISIBLE + " = 1",
null,
CalendarContract.Instances.BEGIN + " ASC");