我的应用需要将信息与日历事件相关联。为此,它需要每个事件的持久ID,以便它可以在时间发生变化时跟踪事件或检测事件何时被删除。
此外,我想要一个日历本地的ID,而不仅仅是特定设备上的唯一ID,因此如果我的应用程序在另一个Android设备或其他平台上运行,它会很有用。
我看过_ID和_SYNC_ID。看起来它们在特定设备上只是唯一且持久的,而不是跨设备。我想要的密钥是本机事件密钥,来自它所属的日历。例如,对于Outlook事件,我认为我想要Outlook的关键。
Calendar api中是否提供了这样的密钥?如果没有,无论如何都要获得我正在寻找的本机密钥?
感谢。
答案 0 :(得分:0)
我可以告诉你,Event_ID和你一样持久。它是PK,因此除非在删除行之后重用PK,否则它应该是可靠的。唯一的例外是用户清除日历数据库和重新同步。在这种情况下,我认为,所有的PK都将是全新的。
以下是CalendarDatabaseHelper.java的一些源代码,显示Event._ID是PK:
db.execSQL("CREATE TABLE Events (" +
"_id INTEGER PRIMARY KEY," +
ACCOUNT_NAME + " TEXT," +
ACCOUNT_TYPE + " TEXT," +
"_sync_id TEXT," +
"_sync_version TEXT," +
"_sync_time TEXT," + // UTC
"_sync_local_id INTEGER," +
"_sync_dirty INTEGER," +
"_sync_mark INTEGER," + // To filter out new rows
"calendar_id INTEGER NOT NULL," +
"htmlUri TEXT," +
"title TEXT," +
"eventLocation TEXT," +
"description TEXT," +
"eventStatus INTEGER," +
"selfAttendeeStatus INTEGER NOT NULL DEFAULT 0," +
"commentsUri TEXT," +
"dtstart INTEGER," + // millis since epoch
"dtend INTEGER," + // millis since epoch
"eventTimezone TEXT," + // timezone for event
"duration TEXT," +
"allDay INTEGER NOT NULL DEFAULT 0," +
"visibility INTEGER NOT NULL DEFAULT 0," +
"transparency INTEGER NOT NULL DEFAULT 0," +
"hasAlarm INTEGER NOT NULL DEFAULT 0," +
"hasExtendedProperties INTEGER NOT NULL DEFAULT 0," +
"rrule TEXT," +
"rdate TEXT," +
"exrule TEXT," +
"exdate TEXT," +
"originalEvent TEXT," + // _sync_id of recurring event
"originalInstanceTime INTEGER," + // millis since epoch
"originalAllDay INTEGER," +
"lastDate INTEGER," + // millis since epoch
"hasAttendeeData INTEGER NOT NULL DEFAULT 0," +
"guestsCanModify INTEGER NOT NULL DEFAULT 0," +
"guestsCanInviteOthers INTEGER NOT NULL DEFAULT 1," +
"guestsCanSeeGuests INTEGER NOT NULL DEFAULT 1," +
"organizer STRING," +
"deleted INTEGER NOT NULL DEFAULT 0," +
"dtstart2 INTEGER," + //millis since epoch, allDay events in local timezone
"dtend2 INTEGER," + //millis since epoch, allDay events in local timezone
"eventTimezone2 TEXT," + //timezone for event with allDay events in local timezone
"syncAdapterData TEXT" + //available for use by sync adapters
");");