![](/img/trans.png)
[英]Google Calendar API: add latitude longitude to Calendar Event programmatically in android?
[英]Google Calendar API android create event
我正在尝试使用Google Calendar API在android App中使用文件(.pdf) 创建事件 : 创建事件
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()));
在云端硬盘中:v3不会退出getALternateLink()在应用中将版本更改为v2
// compile('com.google.apis:google-api-services-drive:v3-rev64-1.22.0') {
// exclude group: 'org.apache.httpcomponents'
// }
把这个
compile('com.google.apis:google-api-services-drive:v2-rev123-1.18.0-rc'){
exclude group: 'org.apache.httpcomponents'
}
对于Drive API V3,您需要获取驱动器文件的元数据。 首先获取驱动器文件,然后获取元数据。 元数据对象具有所有3个值。
Task<Metadata> metadataTask = getDriveResourceClient().getMetadata(driveFile.getDriveId().asDriveResource());
Tasks.await(metadataTask);
Metadata meta = metadataTask.getResult();
Event event = mService.events().get(calendarId, eventId).execute();
List<EventAttachment> attachments = event.getAttachments();
if (attachments == null) {
attachments = new ArrayList<>();
}
Event changes = new Event();
attachments.add(new EventAttachment()
.setFileUrl(meta.getAlternateLink())
.setMimeType(meta.getMimeType())
.setTitle(meta.getTitle()));
changes.setAttachments(attachments);
mService.events()
.patch(calendarId, eventId, changes)
.setSupportsAttachments(true)
.execute();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.