Christopher Masser
Christopher Masser

Reputation: 829

Android Calendar Provider: Is there a unique identifier for events, usable across multiple devices?

I'm using the Android Calendar Provider to display events. I'm also associating the events with images from a local app database by using the EVENT_ID of the event as a reference.

I'm now wondering if it is possible to keep the same reference across multiple devices?

I understand that for the account_type = 'com.google', the GoogleCalendarSyncAdapter uses CalendarContract.EventsColumns.SYNC_DATA1 to store the googleID of the event. However, it seems that this is not a reliable way to access the data since usage of the SYNC_DATA columns may change at any time and can only be modified by the SyncAdapter.

Is there any other way that I can keep the reference to a calendar provider event across devices?

Upvotes: 12

Views: 1003

Answers (1)

tiguchi
tiguchi

Reputation: 5410

Embed image IDs into your events

A while ago I had a similar problem with CalendarContract and I solved it by embedding a unique UID tag into the event description text. Clients would parse that tag and retrieve a common UID. That ID is generated on one of the clients using the UUID Java class. However, in my case I was more interested in identifying events created with my app.

In your case I assume that your image database references are stable IDs that are consistent across all app installations. You could insert a tag into the event description text that references the image from your DB such as:

<myapp:imgid_1234>

Alternatively you could also add a special "resource type" attendee to your event that adds that image reference to an event: [email protected]. This option would keep the event description clean and may lower accidental deletion through the user.

Upvotes: 1

Related Questions