Search code examples
androidandroid-2.2-froyoandroid-sdk-2.3

Trigger Android Calendar to sync after adding events programmatically


I am using the "undocumented" API's to read and write calendar events, nothing too hard there. The problem though is after creating calendar events you have to wait for the polling period (I suppose) for the device to sync it's calendar, such as with gmail, for events to appear online. I have found that if you add an event to the calendar directly it will sync right away so something in the Calendar app is triggering an immediate synchronization.

Is there something I can do in code to notify the device to sync the calendar at completion of adding new events?

Thank you.


Solution

  • The ContentResolver class has various helper methods to deal with syncing. Try ContentResolver.requestSync() method.