I have a strange issue when I create a calendar event programmatically its always noted as Birthday Calendar (type) I don’t have any clue why its noted like that.
My code I use is as below: Xamarin C#
ContentResolver cr = ((Activity)Forms.Context).ContentResolver; ContentValues values = new ContentValues(); String eventUriString = "content://com.android.calendar/events"; //Insert Events in the calendar... values.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 1); values.Put(CalendarContract.Events.InterfaceConsts.Title, title); values.Put(CalendarContract.Events.InterfaceConsts.Status, 1); values.Put(CalendarContract.Events.InterfaceConsts.Description, description); values.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(year, month, day, hour, minute)); values.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(year, month, day, hour, minute)); values.Put(CalendarContract.Events.InterfaceConsts.AllDay, allday ? "1" : "0"); values.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, hasalarm ? "1" : "0"); values.Put(CalendarContract.Events.InterfaceConsts.EventColor, Android.Graphics.Color.Green); values.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "GMT+" + zone + ":00"); values.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "GMT+" + zone + ":00"); cr.Insert(Android.Net.Uri.Parse(eventUriString), values);
Please does someone has any tips or ideas which can point me to the right direction?
Thanks in advance.
Advertisement
Answer
The question answered below is old please refer to Pkosta’s answer which provides more accurate answer …
You have to put CalendarId value as 3 instead of 1 which is default birthday calendar. e.g.
values.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 1);
change it to
values.Put(CalendarContract.Events.InterfaceConsts.CalendarId, 3);
It solved the same issue for me.