0

I want to get all of today's event instances. For that, I'm using the following code:

Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon();
    ContentUris.appendId(eventsUriBuilder, start);
    ContentUris.appendId(eventsUriBuilder, end);
 final Cursor cursorInstances = contentResolver.query(eventsUri, null, null, null, sortOrder);

It's fine except for all day event instances, it returns for both today and tomorrow!

Update I know why is that because time zone of event instances with all day flag is Utc but I'm getting the event in local time so that's why but I still don't know how can I handle that.

Can someone help me out?

max
  • 5,963
  • 12
  • 49
  • 80

1 Answers1

0

Try the code in this SO post answer.

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: 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 search to 11:59PM the previous night and 12:00AM tonight.

MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65