• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Google Calendar API check Availability

I am currently using the Quickstart Google Calendar API

I am trying to check if the events are marked as "free" or "busy"
The full code can Ben found here
https://developers.google.com/google-apps/calendar/quickstart/android

This is a snippet of the method which collects the event data
Code:
            private List<String> getDataFromApi() throws IOException {
           // List the next 10 events from the primary calendar.
            DateTime now = new DateTime(System.currentTimeMillis());
            List<String> eventStrings = new ArrayList<String>();
            Events events = mService.events().list("primary")
                    .setMaxResults(10)
                    .setTimeMin(now)
                    .setOrderBy("startTime")
                    .setSingleEvents(true)
                    .execute();

            List<Event> items = events.getItems();

            for (Event event : items) {
                DateTime start = event.getStart().getDateTime();


                if (start == null) {
                    // All-day events don't have start times, so just use
                    // the start date.
                    start = event.getStart().getDate();
                }
                eventStrings.add(
                        String.format("%s (%s)", event.getSummary(),

            }


            return eventStrings;
        }

I have looked inside the freebusy method within a calendar class

https://developers.google.com/resou.../api/services/calendar/Calendar.Freebusy.html

And tried creating "freebusy requests" and "freebusy" variables, linking them to each event and attempted to create a query

I have also tried using the "CalenderContact.Event.AVAILABILTY"
"CalenderContact.Event.AVAILABILTY_BUSY"
"CalenderContact.Event.AVAILABILTY_FREE"
However I personally think and these have nothing to with it

What do you think? Is there something wrong with my structure ? Any help would be much appreciated :):)
 
Last edited:
Thanks for the link LV426 :D

I have added some of the code inside the link, however for some reason the request is unable to to add the event.
The request only accepts "List <FreeBusyRequestItem>" which I have created, then the List is unable to store the event because it isn't an "List <FreeBusyRequestItem>" O.o

Code:
private List<String> getDataFromApi() throws IOException {
    // List the next 10 events from the primary calendar.
    DateTime now = new DateTime(System.currentTimeMillis());
    List<String> eventStrings = new ArrayList<String>();
    Events events = mService.events().list("primary")
            .setMaxResults(10)
            .setTimeMin(now)
            .setOrderBy("startTime")
            .setSingleEvents(true)
            .execute();

    List<Event> items = events.getItems();

    List <FreeBusyRequestItem> get =null;

    for (Event event : items) {
        DateTime start = event.getStart().getDateTime();
        DateTime end = event.getEnd().getDateTime();

        FreeBusyRequest request = new FreeBusyRequest();

        request.setTimeMin(start);
        request.setTimeMax(end);

        FreeBusyResponse busyTimes;
        try {
            Calendar.Freebusy.Query query = mService.freebusy().query(request);
            // Use partial GET to retrieve only needed fields.
            query.setFields("calendars");
            busyTimes = query.execute();
            // ...
        } catch (IOException e) {
            // ...
        }

I've been trying to wrap my head around this for the past 2 days o_O
 
What's the actual error? Do you get an exception? If so, post the stack trace from the Logcat
 
The only error that is coming up is that it is return null values, the IO exception isn't catching anything
When I get the data from the event, i am getting information such as, "created on","creator","display name","email", "etag", "status" etc

Screen_Shot_2016_09_21_at_12_03_06_PM.png
 
Back
Top Bottom