public void CreateCalendarEvent(CalendarEventModel calEvent)
 {
     try
     {
         Intent intent = new Intent(Intent.ActionInsert);
         intent.SetData(Android.Provider.CalendarContract.Events.ContentUri);
         intent.PutExtra(Android.Provider.CalendarContract.ExtraEventBeginTime, CurrentTimeMillis(calEvent.StartTime));
         intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.AllDay, false);
         intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.HasAlarm, calEvent.HasReminder);
         intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.EventLocation, calEvent.Location);
         intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.Description, calEvent.Description);
         intent.PutExtra(Android.Provider.CalendarContract.ExtraEventEndTime, CurrentTimeMillis(calEvent.EndTime));
         intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.Title, calEvent.Title);
         Xamarin.Forms.Forms.Context.StartActivity(intent);
     }
     catch (Exception ex)
     {
     }
 }
Пример #2
0
        public void CreateCalendarEvent(CalendarEventModel calEvent)
        {
            if (CalendarEvent.eventStore == null)
            {
                CalendarEvent.eventStore = new EKEventStore();
            }

            RequestAccess(EKEntityType.Event, () =>
            {
                EKEvent newEvent = EKEvent.FromStore(CalendarEvent.eventStore);

                if (calEvent.HasReminder)
                {
                    newEvent.AddAlarm(EKAlarm.FromDate(ToNSDate(calEvent.StartTime.AddHours(-1))));
                }

                newEvent.StartDate = ToNSDate(calEvent.StartTime);
                newEvent.EndDate   = ToNSDate(calEvent.EndTime);
                newEvent.Title     = calEvent.Title;
                newEvent.Notes     = calEvent.Description;
                newEvent.Calendar  = CalendarEvent.eventStore.DefaultCalendarForNewEvents;

                NSError e;
                CalendarEvent.eventStore.SaveEvent(newEvent, EKSpan.ThisEvent, out e);
                if (e != null)
                {
                    new UIAlertView("Error Saving Event", e.ToString(), null, "ok", null).Show();
                    return;
                }
                else
                {
                    new UIAlertView("Event Saved", "Event ID: " + newEvent.EventIdentifier, null, "ok", null).Show();
                    Console.WriteLine("Event Saved, ID: " + newEvent.EventIdentifier);
                }

                // to retrieve the event you can call
                EKEvent mySavedEvent = CalendarEvent.eventStore.EventFromIdentifier(newEvent.EventIdentifier);
                Console.WriteLine("Retrieved Saved Event: " + mySavedEvent.Title);
            });
        }