CalendarContract.Events._ID 在 Android 5.0 中缺失

CalendarContract.Events._ID is missing in Android 5.0

我的应用使用 Events._ID 查询 CalendarContract.Events 中的特定事件。在尝试在 5.0 设备上 运行 之前,它运行良好,现在我得到一个异常

01-12 17:28:50.525: E/Unknown Source(18499): android.database.sqlite.SQLiteException:
    no such column: CalendarContract.Events._ID (code 1): ,
    while compiling:
        SELECT _id, account_type, title, organizer, description, eventLocation,
            hasAlarm, calendar_id
        FROM view_events
        WHERE (lastSynced = 0 AND (CalendarContract.Events._ID=1))

查询 Events 中的所有列确实不会 return _ID。知道为什么这已被删除或者它是否是一个错误?我似乎再也找不到唯一标识事件的方法了。

这是我的查询:

String[] projection = new String[]{Events._ID, Events.ACCOUNT_TYPE, Events.TITLE,
        Events.ORGANIZER, Events.DESCRIPTION, Events.EVENT_LOCATION, Events.HAS_ALARM,
        Events.CALENDAR_ID};

Cursor cursor = context.getContentResolver().query(EVENTS_CONTENT_URI, projection,
         "CalendarContract.Events._ID=" + eventId, null, null);

感谢您提供任何信息!

@Andrew 的回答不对。 您错误地使用了 selectionClauseselectionArgs 参数。

这是您正在做的事情:

Cursor cursor = context.getContentResolver().query(EVENTS_CONTENT_URI, projection,
    CalendarContract.Events._ID + "=" + eventId, null, null);

这是你应该做的:

Cursor cursor = context.getContentResolver().query(EVENTS_CONTENT_URI, projection,
    CalendarContract.Events._ID + " = ?", new String[]{eventId}, null);

eventId 需要在 selectionArgs 中传递,以便 contentResolver 可以为您构建查询语句,链接 selectionArgs 并将它们替换为? selectionClause 参数中的字符。

这个问题已经三年了,但我希望我的回答能帮助到别人。