Reading all of today's events using CalendarContract - Android 4.0+

前端 未结 5 958
日久生厌
日久生厌 2020-12-16 01:04

I\'m trying to use Android\'s new calendar API to read all of today\'s calendar events. I\'m have trouble finding the right selection on the database query to return all of

5条回答
  •  失恋的感觉
    2020-12-16 01:53

    To get all events today, including recurring events, you need to use the Instances table, i.e.

    Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI
                .buildUpon();
    ContentUris.appendId(eventsUriBuilder, timeNow);
    ContentUris.appendId(eventsUriBuilder, endOfToday);
    Uri eventsUri = eventsUriBuilder.build();
    Cursor cursor = null;       
    cursor = mContext.getContentResolver().query(eventsUri, columns, null, null, CalendarContract.Instances.DTSTART + " ASC");
    

    Note that you must append the time constraints to the events uri, you cannot sort any other way.

    In order to include all day events as well, just expand the the search to 11:59PM the previous night and 12:00AM tonight.

提交回复
热议问题