添加提醒到日历

发布于 2024-11-07 07:24:07 字数 682 浏览 0 评论 0原文

您好,我目前正在使用以下代码将事件添加到 Android 的默认日历中。

Calendar cal = Calendar.getInstance();              
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", false);
intent.putExtra("rrule", "FREQ=DAILY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
intent.putExtra("description", "Who knows! this might work");
intent.putExtra("eventLocation", "Hope this time it works");
intent.putExtra("hasAlarm", 1);
startActivity(intent);

我的问题是,是否可以编辑此代码以便我可以向日历添加提醒?

Hi I am currently using the following code to add an event to the android's default calendar.

Calendar cal = Calendar.getInstance();              
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", cal.getTimeInMillis());
intent.putExtra("allDay", false);
intent.putExtra("rrule", "FREQ=DAILY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
intent.putExtra("description", "Who knows! this might work");
intent.putExtra("eventLocation", "Hope this time it works");
intent.putExtra("hasAlarm", 1);
startActivity(intent);

My question is, will it be possible to edit this code so that I can add reminder to the calendar?

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

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

发布评论

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

评论(1

不气馁 2024-11-14 07:24:07

这里的论坛中有一些关于如何实现这一目标的帖子。有多种方法,包括使用在谷歌代码中找到的一些API,但我发现了一个似乎更简单的方法,即使我之前没有尝试过并且我不确定但怀疑它触发的警告是基于默认的。但通过一些探索,您应该能够找到一种自定义它的方法。

无论如何,如下所述:如何编辑日历通过 android 应用程序的事件

您应该使用 ContentValues 对象,它作为日历条目

ContentValues event = new ContentValues();

对于此对象,您可以通过以下方式激活闹钟:

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

这篇文章没有提及如何设置闹钟设置,但您可能会能够通过调查哪个字符串来找到它们将 ContentValues 用于日历意图时,可用于 put 方法的键。

完成后,您可以通过以下方式将事件放入日历中:

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

There are some posts in the forums here about how this can be achieved. There are multiple ways, including using some APIs found in google code, but I found what seems to be a simpler method, even though I have not tried it before and I am not sure but suspect that the warning it triggers is based in the default. But with some exploration you should be able to find a way to customize it.

In any case, as mentioned in here: how to edit the calendar events via android application

You should use a ContentValues object, which works as a calendar entry

ContentValues event = new ContentValues();

For this object, you can activate an alarm in this way:

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

The post does not refer how to set the alarm settings, but you might be able to find those by investigating into which string keys you can use for the put method when using ContentValues for a Calendar intent.

Once you are done, you can put the event into the calendar in this way:

Uri eventsUri = Uri.parse("content://calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文