您好,我正在将事件保存到设备的日历中,并希望为添加的事件设置警报或提醒。目前,它正在添加事件,但不显示提醒或不发出警报。
我希望在活动开始5分钟前发出警报或提醒。
public static long pushAppointmentsToCalender(Activity curActivity, String title, String addInfo,
String place, int status, long startDate, boolean needReminder) {
/***************** Event: note(without alert) *******************/
String eventUriString = "content://com.android.calendar/events";
ContentValues eventValues = new ContentValues();
eventValues.put("title", title);
eventValues.put("description", addInfo);
eventValues.put("eventLocation", place);
long endDate = startDate + 1000 * 60 * 60; // For next 1hr
eventValues.put("dtstart", startDate);
eventValues.put("dtend", endDate);
eventValues.put("eventStatus", status); // This information is
eventValues.put("eventTimezone", "UTC +5:30");
eventValues.put("hasAlarm", 1); // 0 for false, 1 for true
Uri eventUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(eventUriString), eventValues);
long eventID = Long.parseLong(eventUri.getLastPathSegment());
if (needReminder) {
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
reminderValues.put("minutes", 5); // Default value of the
reminderValues.put("method",1); // Alert Methods: Default(0),
Uri reminderUri = curActivity.getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}
return eventID;
答案 0 :(得分:0)
您可以查看此documentation中的示例代码,了解如何插入带有提醒的事件。
EventReminder[] reminderOverrides = new EventReminder[] {
new EventReminder().setMethod("email").setMinutes(24 * 60),
new EventReminder().setMethod("popup").setMinutes(10),
};
Event.Reminders reminders = new Event.Reminders()
.setUseDefault(false)
.setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);
以下是一个可能会有所帮助的附加链接:How to create Events in Google Calendar API with Android