Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

android - 如何在Android Studio中将事件添加到Google Calendar API?(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.

(我在业余时间开发应用程序,其中一个要素要求用户能够在应用程序中创建事件,但我希望创建该事件并与Google日历同步。)

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.

(我本质上想添加此内容,但允许用户创建事件以及查看其现有事件。)

  ask by smithcommajohn translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try checking the Google Sample for Calendar API in Android , this explains the basic functions like adding a calendar, editing, update and delete calendar.

(尝试检查Android中Google Sample for Calendar API ,这说明了添加日历,编辑,更新和删除日历等基本功能。)

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.

(另外,我还找到了更详细的教程, 如何将google calendar API集成到android应用程序中,以及如何将 Android日历编程与Calendar 集成 在一起 ,这将帮助您实现使用应用添加事件的代码实现。)

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();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...