我正在尝试在我以编程方式创建的日历上添加一个事件
var uri = CalendarContract.Calendars.ContentUri; ContentValues val = new ContentValues();
val.Put(CalendarContract.Calendars.InterfaceConsts.CalendarAccessLevel, CalendarAccess.AccessOwner.ToString());
val.Put(CalendarContract.Calendars.Name, "Mary");
val.Put(CalendarContract.Calendars.InterfaceConsts.Visible, true);
val.Put(CalendarContract.Calendars.InterfaceConsts.SyncEvents, true);
val.Put(CalendarContract.Calendars.InterfaceConsts.CalendarColor, "0xff00ffff");
val.Put(CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, "Mary");
uri = uri.BuildUpon()
.AppendQueryParameter(CalendarContract.CallerIsSyncadapter, "true")
.AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.AccountName, AccountName)
.AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.AccountType, CalendarContract.AccountTypeLocal)
.Build();
var calresult = ContentResolver.Insert(uri, val);
calID = int.Parse(calresult.LastPathSegment);
AddCalendarEvent( calID);
它被成功添加,我可以看到这个日历
我正在添加这样的事件,
ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, calID);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, "Test Event from M4A");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, "This is an event created from Mono for Android");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(2013, 9, 15, 10, 0));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(2013, 9, 15, 11, 0));
// GitHub issue #9 : Event start and end times need timezone support.
// https://github.com/xamarin/monodroid-samples/issues/9
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "UTC");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "UTC");
var uri = ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);
Console.WriteLine("Uri for new event: {0}", uri);
我的问题是,当我尝试打开此活动以查看说明时,它给了我一个错误“不幸的是日历已停止”。当它被添加到默认日历时,我可以打开它。我在创建日历时做错了什么?我遵循了这个博客的代码,http://www.derekbekoe.co.uk/blog/16-using-the-android-4-0-calendar-api#part4,但它仍然给了我同样的错误。我使用的是安卓 4.2.2