I'd like to sync between the internal Android calendar and my application. I'm using CalendarContract available from Android API 14 onwards.
Any change of the content provider "com.android.calendar" calls onPerformSync(..) of my sync adapter. However, at this point, all the rows of the events are set DIRTY = 0. That means, the Google calendar sync must have set the DIRTY FLAG to zero before my sync adapter can access them.
CalendarContract.EventsColumns.SYNC_DATA1 - SYNCDATA10 are said to be columns of the content provider for use with sync adapters. Does anybody know if there is some convention for what is the use of these columns? I've realized that on my device SYNC_DATA5 stores the date last modified and SYNC_DATA1 seems to store the Google event ID. So it seems whenever the Calendar app syncs with Google Calendar, these columns are modified.
However, if I choose to use one of these columns for my sync adapter, how can I make sure another application doesn't use the very same columns and they override each other?
If SYNC_DATA5 is ALWAYS used by Google Calendar to store the date last modified I would be fine with just using that for my sync logic, I just need to be certain that this is a convention.
The SYNC_DATA
columns can be used for any value. I'm not sure on how the google calendar does that, but they are intended for stuff related to your sync adapter, applications not syncing the calendar must not use them. So you're safe to use any column (given you don't change it between versions of your application, or you'd have to write migration code), as there should not be any other sync adapters working on your calendar.
You can not rely on the SYNC_DATA
columns when not being a sync adapter, do not use them when the calendar is not "yours".
However, I have a strong feeling you're not syncing properly. To sync a calendar, you must use a separate calendar, not any calendar synced by google or any other third party app. I'll also list some other steps involved which I think you performed, but may be helpful to others.
You also need to append some parameters to any of your requests for the system so you get access to the sync adapter fields. Also, you should sync your calendar from an AbstractThreadedSyncAdapter
implementation only. For that, you also need to provide an authenticator, if you have none yet (so the user will be able to enable/disable your sync adapter in the sync preferences of an account). An overview on the sync adapter thing can be found in this blog post.
If you don't have server-side accounts and only one calendar, you need to do some stuff when starting up for the first time:
After that, Android will take care of executing your sync adapter from time to time, and you can access the SYNC_DATA
columns without collisions (in the calendar you created) and DIRTY
flags are served properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With