添加日历提醒

时间:2011-05-13 06:50:40

标签: android google-calendar-api reminders

您好我正在使用以下代码将事件添加到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);

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

1 个答案:

答案 0 :(得分:2)

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

无论如何,如此处所述:how to edit the calendar events via android application

您应该使用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);
相关问题