Sync with Android Calendar Sync Server - SYNC_DATA?

I want to sync between the internal Android calendar and my application. I am using CalendarContract, available from Android API 14 onwards.

Any change to the content provider "com.android.calendar" calls onPerformSync (..) of my sync adapter. However, at the moment, all event lines are set to DIRTY = 0. This means that Google Calendar synchronization had to set DIRTY FLAG to zero before the synchronization adapter could access them.

CalendarContract.EventsColumns.SYNC_DATA1 - SYNCDATA10 are called content provider columns for use with synchronization adapters. Does anyone know if there is some kind of convention for using these columns? I realized that on my device, SYNC_DATA5 stores the date of the last change, and SYNC_DATA1 seems to store the Google event id. Thus, whenever the Calendar app syncs with Google Calendar, these columns change.

However, if I decide to use one of these columns for my sync adapter, how can I make sure that the other application is not using the same columns and they override each other?

If SYNC_DATA5 is ALWAYS used by Google Calendar to store the last modified date, I would be fine if I used this for my synchronization logic, I just need to be sure that this is a convention.

+4
source share
1 answer

SYNC_DATA columns can be used for any value. I'm not sure how this works on Google Calendar, but they are for materials related to your sync adapter, non-sync calendar apps should not use them. Thus, you can use any column (if you do not change it between versions of your application or you have to write a migration code), since there should not be any other synchronization adapters in your calendar.

You cannot rely on SYNC_DATA columns if you are not a synchronization adapter, do not use them when the calendar is not “yours”.


However, I have a strong feeling that you are not synchronized properly. To sync a calendar, you must use a separate calendar , not any calendar synced by Google or any other third-party application. I will also list some other actions that I think you have performed, but which may be useful to others.

You also need to add some parameters to any of your queries for the system so that you can access the fields of the synchronization adapter. In addition, you should only synchronize the calendar with the AbstractThreadedSyncAdapter implementation . To do this, you also need to provide an authenticator, if you do not already have one (so that the user can enable / disable your synchronization adapter in the account synchronization settings). An overview of this stuff can be found in this blog post .

If you do not have accounts on the server and only one calendar, you need to do some things when starting for the first time:

  • Create an account
  • Create a calendar associated with this account
  • Enabling the sync adapter

After that, Android will take care of the execution of your synchronization adapter from time to time, and you can access the SYNC_DATA columns without conflicts (in the created calendar) and the DIRTY flags will be served properly.

+1
source

Source: https://habr.com/ru/post/1445521/


All Articles