0
votes

Hello I am saving events to device's calendar and wants to set alarm or reminders for the event added. Currently it's adding events but not showing reminders or does not play alarm.

I am expecting an alarm or reminder before 5 minutes from the time of event.

 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;
1
did you check if the reminder data is saved into the event when it's saved to google, and if it's as you expected? BTW this appears to be Android calendar not google calendar.ADyson

1 Answers

0
votes

You may check the sample code in this documentation on how to insert an event with reminders.

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);

Here's an additional link which might help: How to create Events in Google Calendar API with Android