将 .ics 文件导入 android 设备上的 google 日历
Import .ics-file into google calendar on android device
我有一个 android 应用程序,它管理和显示本地 SQLite 数据库中的数据等事件。
我想为我的客户提供将数据从数据库转换为 .ics 文件并将该文件导入日历的选项。
我知道如何从我的数据库中创建和存储有效的 .ics 文件。
我的问题是将该文件导入 google 或任何其他日历。
我不想创建自定义本地日历,我只是想 "open" ics 文件,以便用户可以选择日历或让数据直接导入。
用户交互 -> .ics 文件创建 -> 将所有事件导入日历
有什么建议吗?这甚至可能吗?
几周前我遇到了同样的问题。我找到了如何将单个任务或事件导出到 Google 日历。检查全部信息here
我引用上面link的日历添加事件的方式:
To add an entry to a specific calendar, we need to configure a
calendar entry to insert using the ContentValues as follows:
ContentValues event = new ContentValues();
Each event needs to be tied to a specific Calendar, so the first thing
you're going to want to set is the identifier of the Calendar to
insert this event into:
event.put("calendar_id", calId);
We then set some of the basic information about the event, including
String fields such as the event title, description and location.
event.put("title", "Event Title");
event.put("description", "Event Desc");
event.put("eventLocation", "Event Location");
There are a number of different options for configuring the time and
date of an event.
We can set the event start and end information as follows:
long startTime = START_TIME_MS;
long endTime = END_TIME_MS;
event.put("dtstart", startTime);
event.put("dtend", endTime);
If we are adding a birthday or holiday, we would set the entry to be
an all day event:
event.put("allDay", 1); // 0 for false, 1 for true
This information is sufficient for most entries. However, there are a
number of other useful calendar entry attributes.
For example, you can set the event status to tentative (0), confirmed
(1) or canceled (2):
event.put("eventStatus", 1);
You can control who can see this event by setting its visibility to
default (0), confidential (1), private (2), or public (3):
event.put("visibility", 0);
You can control whether an event consumes time (can have schedule
conflicts) on the calendar by setting its transparency to opaque (0)
or transparent (1).
event.put("transparency", 0);
You can control whether an event triggers a reminder alarm as follows:
event.put("hasAlarm", 1); // 0 for false, 1 for true
Once the calendar event is configured correctly, we're ready to use
the ContentResolver to insert the new calendar entry into the
appropriate Uri for calendar events:
Uri eventsUri = Uri.parse("content://calendar/events"); Uri url =
getContentResolver().insert(eventsUri, event);
The call to the insert() method contacts the Calendar content provider
and attempts to insert the entry into the appropriate user Calendar.
If you navigate to the Calendar application and launch it, you should
see your calendar entry in the appropriate Calendar. Since the
Calendar syncs, you will also see the Calendar entry online, if you're
using the Google Calendar on the web.
您可以查看 import
service of Google Calendar API. It will require the calendarId
which is explained on the Getting Started 页面。
请求正文将包含您要附加的文件(尽管它仅限于 Google 驱动器,因此您可能还想查看 Drive API)
Events
资源attachments
字段描述
attachments[] list File attachments for the event. Currently only Google Drive attachments are supported.
In order to modify attachments the supportsAttachments request parameter should be set to true.
There can be at most 25 attachments per event,
我有一个 android 应用程序,它管理和显示本地 SQLite 数据库中的数据等事件。
我想为我的客户提供将数据从数据库转换为 .ics 文件并将该文件导入日历的选项。
我知道如何从我的数据库中创建和存储有效的 .ics 文件。
我的问题是将该文件导入 google 或任何其他日历。 我不想创建自定义本地日历,我只是想 "open" ics 文件,以便用户可以选择日历或让数据直接导入。
用户交互 -> .ics 文件创建 -> 将所有事件导入日历
有什么建议吗?这甚至可能吗?
几周前我遇到了同样的问题。我找到了如何将单个任务或事件导出到 Google 日历。检查全部信息here
我引用上面link的日历添加事件的方式:
To add an entry to a specific calendar, we need to configure a calendar entry to insert using the ContentValues as follows:
ContentValues event = new ContentValues();
Each event needs to be tied to a specific Calendar, so the first thing you're going to want to set is the identifier of the Calendar to insert this event into:
event.put("calendar_id", calId);
We then set some of the basic information about the event, including String fields such as the event title, description and location.
event.put("title", "Event Title"); event.put("description", "Event Desc"); event.put("eventLocation", "Event Location");
There are a number of different options for configuring the time and date of an event.
We can set the event start and end information as follows:
long startTime = START_TIME_MS; long endTime = END_TIME_MS; event.put("dtstart", startTime); event.put("dtend", endTime);
If we are adding a birthday or holiday, we would set the entry to be an all day event:
event.put("allDay", 1); // 0 for false, 1 for true
This information is sufficient for most entries. However, there are a number of other useful calendar entry attributes.
For example, you can set the event status to tentative (0), confirmed (1) or canceled (2):
event.put("eventStatus", 1);
You can control who can see this event by setting its visibility to default (0), confidential (1), private (2), or public (3):
event.put("visibility", 0);
You can control whether an event consumes time (can have schedule conflicts) on the calendar by setting its transparency to opaque (0) or transparent (1).
event.put("transparency", 0);
You can control whether an event triggers a reminder alarm as follows:
event.put("hasAlarm", 1); // 0 for false, 1 for true
Once the calendar event is configured correctly, we're ready to use the ContentResolver to insert the new calendar entry into the appropriate Uri for calendar events:
Uri eventsUri = Uri.parse("content://calendar/events"); Uri url = getContentResolver().insert(eventsUri, event);
The call to the insert() method contacts the Calendar content provider and attempts to insert the entry into the appropriate user Calendar. If you navigate to the Calendar application and launch it, you should see your calendar entry in the appropriate Calendar. Since the Calendar syncs, you will also see the Calendar entry online, if you're using the Google Calendar on the web.
您可以查看 import
service of Google Calendar API. It will require the calendarId
which is explained on the Getting Started 页面。
请求正文将包含您要附加的文件(尽管它仅限于 Google 驱动器,因此您可能还想查看 Drive API)
Events
资源attachments
字段描述
attachments[] list File attachments for the event. Currently only Google Drive attachments are supported. In order to modify attachments the supportsAttachments request parameter should be set to true.
There can be at most 25 attachments per event,