Felix
Felix

Reputation: 105

Check if an calendar event is going on

I need to check if there is currently an calendar event that is "busy".

String[] projection = new String[] { BaseColumns._ID};
String selection = CalendarContract.Events.DTSTART + " <= ? AND "
        + CalendarContract.Events.DTEND + ">= ? AND "
        + CalendarContract.Events.AVAILABILITY + "=="
        + CalendarContract.Events.AVAILABILITY_BUSY;

Cursor cur = ctx.getContentResolver().query(CalendarContract.Events.CONTENT_URI,
        projection,
        selection,
        new String[] {String.valueOf(System.currentTimeMillis()),
        String.valueOf(System.currentTimeMillis())},
        null);

This code works fine, but not for recurring events. How can I solve this?

Upvotes: 1

Views: 71

Answers (1)

David Medenjak
David Medenjak

Reputation: 34532

I think all you need to do is switch the table you read from, see here.

CalendarContract.Instances should provide all the events including recurring ones

This table holds the start and end time for each occurrence of an event. Each row in this table represents a single event occurrence. For one-time events there is a 1:1 mapping of instances to events. For recurring events, multiple rows are automatically generated that correspond to multiple occurrences of that event.

Upvotes: 1

Related Questions