Reputation: 9629
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.
Upvotes: 3
Views: 5105
Reputation: 6073
public void syncCalendars()
{
Account[] accounts = AccountManager.get(context).getAccounts();
Log.d(TAG, "Refreshing " + accounts.length + " accounts");
String authority = CalendarContract.Calendars.CONTENT_URI.getAuthority();
for (int i = 0; i < accounts.length; i++) {
Log.d(TAG, "Refreshing calendars for: " + accounts[i]);
Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
ContentResolver.requestSync(accounts[i], authority, extras);
}
}
Upvotes: 3
Reputation: 1516
The ContentResolver class has various helper methods to deal with syncing. Try ContentResolver.requestSync() method.
Upvotes: 2