Android Calendar Provider does not return latest data

Viewed 483

I am using the following code:

String selection = "((dtstart >= " + now
        + ") AND (dtend <= " + endTime.getTimeInMillis() + "))";
Cursor cursor = context.getContentResolver()
        .query(Uri.*parse*("content://com.android.calendar/events"),
                *PROJECTION*, selection,null, null);

And I notice that once I add/remove an Event to Google Calendar app on the device and run the above code immediately, occasionally I do not get the latest dataset from the Cursor. I have to manually refresh the Google Calendar app to get the latest data.

Am I missing something? Can I use some other APIs?

Thanks!

2 Answers

You are right. From some reasons, whether it's a bug or a "feature" - Google calendar provider in last 4-5 months DOES NOT expose changes via CalendarContract until after they have synced with their server.

Before it was not like this, all changes were instantly available for 3rd party apps via CalendarContract - now only after syncing. It is very annoying...You never know if you have fresh data unless you manually perform synchronizing in Google Calendar app (or you can wait until auto-syncing triggers - which can be within seconds, minutes or hours, it is not in your hands).

Such a stupid, stupid change. Classic google. They screwed up so many things already, this is just another one. They just complicate life for devs.

To get latest data after adding event to calendar you can listen calendar for event changes

Related