Why duration is NULL for recurrent event in androi

2019-02-26 03:49发布

问题:

I try to implement one way synchronization with android calendar events (I need original events - not event instances). So, I have the following query:

String[] projection = new String[]{
                    CalendarContract.Events.DTSTART,
                    CalendarContract.Events.EVENT_TIMEZONE,
                    CalendarContract.Events.DTEND,
                    CalendarContract.Events.EVENT_END_TIMEZONE,
                    CalendarContract.Events.DURATION
            };
String selection = null;
String[] args = new String[0];
String sort = CalendarContract.Events.DTSTART + " ASC";
Cursor cursor = getContentResolver().query(CalendarContract.Events.CONTENT_URI, projection, selection, args, sort);

According to developer docs for recurrent events dtstart and duration are required but when I create event through Google calendar and receive it later in my code I have dtend = 0 and duration = null.

Integer dtend = cursor.getLong(2);
String duration = cursor.getString(4);

Why it may happen?

回答1:

I have an issue with indexes in my original application. CalendarContract.Events.DURATION column solves the problem. It has single event duration in RFC2445 format. I just need to parse it.