添加提醒到日历
您好,我目前正在使用以下代码将事件添加到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的论坛中有一些关于如何实现这一目标的帖子。有多种方法,包括使用在谷歌代码中找到的一些API,但我发现了一个似乎更简单的方法,即使我之前没有尝试过并且我不确定但怀疑它触发的警告是基于默认的。但通过一些探索,您应该能够找到一种自定义它的方法。
无论如何,如下所述:如何编辑日历通过 android 应用程序的事件
您应该使用 ContentValues 对象,它作为日历条目
对于此对象,您可以通过以下方式激活闹钟:
这篇文章没有提及如何设置闹钟设置,但您可能会能够通过调查哪个字符串来找到它们将 ContentValues 用于日历意图时,可用于 put 方法的键。
完成后,您可以通过以下方式将事件放入日历中:
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
For this object, you can activate an alarm in this way:
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: