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

1

12

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?

Norahnorbert answered 24/7, 2013 at 10:51 Comment(0)
K
1

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.

Kliman answered 17/1, 2014 at 17:11 Comment(2)
Thanks, this is quite some hack, but probably the only way of doing it. The problem is that other apps can display, modify or delete the attendee, so it's probably not worth the risk.Norahnorbert
@ChristopherMasser Don't worry about other apps, worry about the user and tell them not to delete these automatically generated attendees since it's in their own interest. From a CalendarContract API point of view there is - to my knowledge - no other way to add meta-information to an event. Only SyncAdapters have that privilege. You could however interface the Google Calendar API directly and use the extendedProperties object that can hold app-specific key-value pairs of arbitrary data. See here: developers.google.com/google-apps/calendar/v3/reference/eventsKliman

© 2022 - 2024 — McMap. All rights reserved.