【发布时间】:2017-03-28 10:20:44
【问题描述】:
我正在尝试使用 Google Calendar API 在 android App 中创建一个带有文件 a (.pdf) 的事件:Create Events
public static void addAttachment(Calendar calendarService, Drive driveService, String calendarId,
String eventId, String fileId) throws IOException {
File file = driveService, android .files().get(fileId).execute();
Event event = calendarService.events().get(calendarId, eventId).execute();
List<EventAttachment> attachments = event.getAttachments();
if (attachments == null) {
attachments = new ArrayList<EventAttachment>();
}
attachments.add(new EventAttachment()
.setFileUrl(file.getAlternateLink())
.setMimeType(file.getMimeType())
.setTitle(file.getTitle()));
Event changes = new Event()
.setAttachments(attachments);
calendarService.events().patch(calendarId, eventId, changes)
.setSupportsAttachments(true)
.execute();
}
我完全复制了这个但它不起作用,Android Studio 放入红色的 getAlternateLink() 并且 getTitle() 没有重新调整,特别是以下行:
attachments.add(new EventAttachment()
.setFileUrl(file.getAlternateLink())
.setMimeType(file.getMimeType())
.setTitle(file.getTitle()));
【问题讨论】:
-
究竟是什么不起作用?有什么例外吗?
-
Android Studio 放入红色的 getAlternateLink() 和 getTitle()
-
从您复制代码的文档中,here 声明“在将附件支持添加到您现有的在本地存储事件的应用程序。如果您不先执行同步,您可能会无意中从用户的事件中删除现有附件。另外,请注意,您正在执行的代码演示了如何更新现有事件以添加附件。
标签: java android google-api google-calendar-api