1

我正在向日历条目添加提醒。我正在使用这段代码,

 ContentValues eventValues = new ContentValues();
            eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, _calId);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, "Test Event");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, "This is an event created for demo app");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(DateTime.Today, DateTime.Now));
            eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(DateTime.Today.AddDays(1), DateTime.Now));
            eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, true);
            eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "Local");
            eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "Local");
            var eventUri = ContentResolver.Insert(CalendarContract.Events.ContentUri,
                                           eventValues);
            long eventID = long.Parse(eventUri.LastPathSegment);
            string reminderUriString = "content://com.android.calendar/reminders";
            ContentValues reminderValues = new ContentValues();
           // reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.CalendarId, _calId);
            reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, eventID);
            reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Method, RemindersMethod.Alert.ToString());
            reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, 5);
            Android.Net.Uri url = Android.Net.Uri.Parse(reminderUriString);
            var reminderUri = ContentResolver.Insert(url, reminderValues);

这没有给出任何例外,但也没有添加提醒。怎么了?我如何添加提醒?我确实有写权限。我可以添加日历事件但无法添加提醒

4

1 回答 1

1

RemindersMethod 是一个枚举,因此您需要将其转换为一个 int。

因此,将添加 Reminder 方法的代码更改为:

remindersValues.Put(
  CalendarContract.Reminders.InterfaceConsts.Method,
  (int) RemindersMethod.Alert
);
于 2015-12-20T17:36:58.927 回答