2
votes

I'm using this Microsoft Graph Tutorial for viewing Microsoft Calendar events using Android Studio. I finished the tutorial already and am wondering how to create events.

I'm currently trying to use the Event object to create events. I'm trying to use the following code from this GitHub repo:

Event event = new Event();
event.setSubject("Today's appointment");
event.setStart(dtz);
event.setImportance(Importance.High);
event.setIsReminderOn(true);
event.setReminderMinutesBeforeStart(15);

to create the event for this code:

Event addedEvent = client.getMe().getCalendars().getById("Calendar").getEvents().add(event).get();

But it seems like the set functions aren't available anymore and I can't find any other tutorials/resources for this. Any help would be greatly appreciated.

Thank you.

1

1 Answers

1
votes

The github repo you're using for help doesn't use the Java Graph SDK found here.The code sample below should however help you to create an event if you build your solution on top of the android sample you were first using.

Essentially the models in the sdk have properties that can be modified directly through assignment and we use the post(event) to send it over via a POST http method.

Event event = new Event();
event.subject = "Let's go for lunch";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Does late morning work for you?";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2017-04-15T12:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2017-04-15T14:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
Location location = new Location();
location.displayName = "Harry's Bar";
event.location = location;

graphClient.me().events()
    .buildRequest()
    .post(event);

This github repo could also be a great help as it has a number of great snippets :) https://github.com/microsoftgraph/android-java-snippets-sample