代号一:使用 Google 日历
Codename One: Use Google Calendar
我想在登录后访问用户的 Google 日历,因为我想在我的 Apps 事件 class 中反映某些标记的事件。
我猜Google日历APIJava库不能简单地用在这里,所以我被代号一支持送到了this Library。
有没有人有这个库的经验或代码示例?
如果没有这个库,你们是如何处理对 Google 日历 API 的访问的?
我在这方面做了一些初步工作,但没有跟上其他作者所做的更改,所以我不能说我对这个库有实际经验...
从代码来看,类似这样的东西应该可以工作:
DeviceCalendar dc = DeviceCalendar.getInstance();
if(!dc.hasPermissions()) {
// show message
return;
}
String calName = Preferences.get("selectedCalendar", null);
if(calName == null) {
Collection<String> calendarNames = dc.getCalendars()
calName = promptUserToPickCalendar(calendarNames);
if(calName == null) {
return;
}
Preferences.set("selectedCalendar", calName);
}
String calId = dc.openCalendar(calName, false);
Collection<EventInfo> events = dc.getEvents(calId, startDate, endDate);
// merge your events then use removeEvent/saveEvent respectively to apply your changes
我想在登录后访问用户的 Google 日历,因为我想在我的 Apps 事件 class 中反映某些标记的事件。
我猜Google日历APIJava库不能简单地用在这里,所以我被代号一支持送到了this Library。
有没有人有这个库的经验或代码示例? 如果没有这个库,你们是如何处理对 Google 日历 API 的访问的?
我在这方面做了一些初步工作,但没有跟上其他作者所做的更改,所以我不能说我对这个库有实际经验...
从代码来看,类似这样的东西应该可以工作:
DeviceCalendar dc = DeviceCalendar.getInstance();
if(!dc.hasPermissions()) {
// show message
return;
}
String calName = Preferences.get("selectedCalendar", null);
if(calName == null) {
Collection<String> calendarNames = dc.getCalendars()
calName = promptUserToPickCalendar(calendarNames);
if(calName == null) {
return;
}
Preferences.set("selectedCalendar", calName);
}
String calId = dc.openCalendar(calName, false);
Collection<EventInfo> events = dc.getEvents(calId, startDate, endDate);
// merge your events then use removeEvent/saveEvent respectively to apply your changes