CalendarContract有时会返回空值

时间:2017-08-31 10:43:01

标签: null calendar cursor calendarcontract

我的日历光标有问题。有时,在查询日历事件,与会者或日历详细信息的数据时,游标会返回空值。

示例

声明日历参加者光标

val projection = arrayOf(
CalendarContract.Attendees.ATTENDEE_ID, 
CalendarContract.Attendees.ATTENDEE_EVENT_ID,
CalendarContract.Attendees.ATTENDEE_NAME, 
CalendarContract.Attendees.ATTENDEE_EMAIL,
CalendarContract.Attendees.ATTENDEE_RELATIONSHIP, 
CalendarContract.Attendees.ATTENDEE_TYPE,
CalendarContract.Attendees.ATTENDEE_STATUS)
val attendeesCursor = 
context.contentResolver.query(CalendarContract.Attendees.CONTENT_URI, 
        projection, 
        CalendarContract.Attendees.EVENT_ID + "=?", 
        arrayOf(eventId.toString()), // eventiId is sent as param
        null
)
if (attendeesCursor != null && attendeesCursor.isBeforeFirst) {
    attendeesCursor.moveToFirst()
}
return attendeesCursor

提供与会者详细信息

                val attendee = EventAttendee(
                    cursor.getLong(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_ID)),
                    cursor.getLong(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_EVENT_ID)),
                    cursor.getString(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_NAME)) ?,
                    cursor.getString(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_EMAIL)),
                    cursor.getInt(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_RELATIONSHIP)),
                    cursor.getInt(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_TYPE)),
                    cursor.getInt(cursor.getColumnIndex(CalendarContract.Attendees.ATTENDEE_STATUS))
            )

有时,一些参加者的详细信息是空的......我没有 知道为什么......

怎么可能?怎么避免这个?

0 个答案:

没有答案