如何通过 Android 应用程序编辑日历事件

发布于 2024-10-30 09:16:43 字数 73 浏览 1 评论 0原文

我如何通过 Android 应用程序编辑日历中的日历事件。

任何人都知道如何在日历应用程序中打开议程活动......

how can i edit the calendar events in calendar via android application..

Any one know how to open the Agenda Activity in the calendar application.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

香橙ぽ 2024-11-06 09:16:43

从日历中读取数据后,试试这个..

将单次事件添加到日历

要将条目添加到特定日历,我们需要配置要使用 ContentValues 插入的日历条目,如下所示:

ContentValues event = new ContentValues();

每个事件都需要与特定日历相关联,因此您要做的第一件事是我们要设置的是要插入此事件的日历的标识符:

event.put("calendar_id", calId);

然后,我们设置有关该事件的一些基本信息,包括字符串字段,例如事件标题、描述和位置。

event.put("title", "Event Title");
event.put("description", "Event Desc");
event.put("eventLocation", "Event Location");

有许多不同的选项可用于配置事件的时间和日期。

我们可以按如下方式设置事件开始和结束信息:

long startTime = START_TIME_MS;
long endTime = END_TIME_MS;
event.put("dtstart", startTime);
event.put("dtend", endTime);

如果要添加生日或假期,我们会将条目设置为全天事件:

event.put("allDay", 1);   // 0 for false, 1 for true

此信息对于大多数条目来说已经足够了。但是,还有许多其他有用的日历条目属性。

例如,您可以将事件状态设置为暂定 (0)、已确认 (1) 或已取消 (2):

event.put("eventStatus", 1);

您可以通过将事件的可见性设置为默认 (0)、机密 (1)、私有 ( 2) 或公共 (3):

event.put("visibility", 0);

您可以通过将事件的透明度设置为不透明 (0) 或透明 (1) 来控制日历上的事件是否消耗时间(可能存在计划冲突)。

event.put("transparency", 0);

您可以控制事件是否触发提醒警报,如下所示:

event.put("hasAlarm", 1); // 0 for false, 1 for true

正确配置日历事件后,我们就可以使用 ContentResolver 将新的日历条目插入到日历事件的相应 Uri 中:

  Uri eventsUri = Uri.parse("content://calendar/events");
  Uri url = getContentResolver().insert(eventsUri, event);

调用 insert()方法联系日历内容提供者并尝试将条目插入到适当的用户日历中。如果您导航到日历应用程序并启动它,您应该在相应的日历中看到您的日历条目。由于日历同步,如果您在网络上使用 Google 日历,您还会在线看到日历条目。

向日历添加重复事件

您还可以配置重复日历事件。为此,您必须以重复规则的形式向事件添加更多字段。规则规范基于 RFC2445

After reading the data from the Calendar just try this out..

Adding a Single-Occurrence Event to a Calendar

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.

Adding a Recurring Event to a Calendar

You can also configure recurring Calendar events. In order to do so, you must add several more fields to the event in the form of a recurrence rule. The rule specification is based upon RFC2445.

海拔太高太耀眼 2024-11-06 09:16:43

这是这个问题的确切答案

    Uri uri = Uri.parse("content://calendar/events");
    long eventId = calendeeventid;
    Uri newuri = ContentUris.withAppendedId(uri, eventId);
    Intent intent = new Intent(Intent.ACTION_VIEW,newuri);
    Cursor cursor = getContentResolver().query(newuri, new String[]{"dtstart","dtend",},null, null, null);
    if(cursor.getCount()>0)
    {   cursor.moveToFirst();
    intent.putExtra("beginTime", cursor.getLong(cursor.getColumnIndex("dtstart")));
    intent.putExtra("endTime",  cursor.getLong(cursor.getColumnIndex("dtend")));
    }

this is the exact answer for this question

    Uri uri = Uri.parse("content://calendar/events");
    long eventId = calendeeventid;
    Uri newuri = ContentUris.withAppendedId(uri, eventId);
    Intent intent = new Intent(Intent.ACTION_VIEW,newuri);
    Cursor cursor = getContentResolver().query(newuri, new String[]{"dtstart","dtend",},null, null, null);
    if(cursor.getCount()>0)
    {   cursor.moveToFirst();
    intent.putExtra("beginTime", cursor.getLong(cursor.getColumnIndex("dtstart")));
    intent.putExtra("endTime",  cursor.getLong(cursor.getColumnIndex("dtend")));
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文