'How can I add an event to the Google Calendar API in Android Studio?

I'm developing an app in my spare time and one of the elements requires a user to be able to create an event within the app but I want the event to be created and synced with the google calendar.

I have followed the quickstart guide but that only shows a list of current events. I essentially want to add to this but allow a user to create an event as well as view their existing ones.



Solution 1:[1]

Try checking the Google Sample for Calendar API in Android, this explains the basic functions like adding a calendar, editing, update and delete calendar. Also I've found more detailed tutorials How to integrate google calendar api in android application and Android Tutorial–Programming with Calendar that will help you with code implementation of adding events using your app.

Add event code:

void insertEvent(String summary, String location, String des, DateTime startDate, DateTime endDate, EventAttendee[] eventAttendees) throws IOException {
    Event event = new Event()
            .setSummary(summary)
            .setLocation(location)
            .setDescription(des);     EventDateTime start = new EventDateTime()
            .setDateTime(startDate)
            .setTimeZone(“America/Los_Angeles”);
    event.setStart(start);     EventDateTime end = new EventDateTime()
            .setDateTime(endDate)
            .setTimeZone(“America/Los_Angeles”);
    event.setEnd(end);     String[] recurrence = new String[] {“RRULE:FREQ=DAILY;COUNT=1”};
    event.setRecurrence(Arrays.asList(recurrence));     event.setAttendees(Arrays.asList(eventAttendees));     EventReminder[] reminderOverrides = new EventReminder[] {
            new EventReminder().setMethod(“email”).setMinutes(24 * 60),
            new EventReminder().setMethod(“popup”).setMinutes(10),
    };
    Event.Reminders reminders = new Event.Reminders()
            .setUseDefault(false)
            .setOverrides(Arrays.asList(reminderOverrides));
    event.setReminders(reminders);     String calendarId = “primary”;
    //event.send
if(mService!=null)
      mService.events().insert(calendarId, event).setSendNotifications(true).execute();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mr.Rebot