0

我的应用需要将信息与日历事件相关联。为此,它需要每个事件的持久 ID,以便它可以在事件时间更改时跟踪事件或检测事件何时被删除。

此外,我想要一个日历原生的 id,而不仅仅是特定设备上的唯一 ID,这样如果我的应用程序在另一个 android 设备甚至另一个平台上运行,它就会很有用。

我查看了 _ID 和 _SYNC_ID。似乎两者都仅在特定设备上是唯一且持久的,而不是跨设备。我想要的键是本机事件键,来自它所属的日历。例如,对于 Outlook 事件,我想我想要 Outlook 的密钥。

日历 api 是否提供这样的密钥?如果没有,是否有办法获得我正在寻找的本机密钥?

谢谢。

4

1 回答 1

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
            ");");
于 2012-12-24T05:25:36.707 回答