我可以知道
的帐户名称是什么吗?CalendarContract.Calendars.InterfaceConsts.AccountName
在xamarin android中?
是" xxx@email.com"?因为我尝试将新事件添加到链接到本地电话日历的特定Gmail帐户,但无法添加。 Code refer to this source
我的代码:
var uri = CalendarContract.Calendars.ContentUri;
ContentValues val = new ContentValues();
val.Put(CalendarContract.Calendars.InterfaceConsts.AccountName, AccountName);
val.Put(CalendarContract.Calendars.InterfaceConsts.AccountType, CalendarContract.AccountTypeLocal);
val.Put(CalendarContract.Calendars.Name, "newww Calendar");
val.Put(CalendarContract.Calendars.InterfaceConsts.CalendarDisplayName, "XXX");
val.Put(CalendarContract.Calendars.InterfaceConsts.CalendarColor, Android.Graphics.Color.Red);
val.Put(CalendarContract.Calendars.InterfaceConsts.OwnerAccount, AccountName);
val.Put(CalendarContract.Calendars.InterfaceConsts.Visible, true);
val.Put(CalendarContract.Calendars.InterfaceConsts.SyncEvents, true);
uri = uri.BuildUpon()
.AppendQueryParameter(CalendarContract.CallerIsSyncadapter, "true")
.AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.AccountName, AccountName)
.AppendQueryParameter(CalendarContract.Calendars.InterfaceConsts.AccountType, CalendarContract.AccountTypeLocal)
.Build();
var calres = ContentResolver.Insert(uri, val);
ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId,
calendarId);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title,
"Test");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description,
"This is a test event");
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart,
GetDateTimeMS(2018, 6, 15, 10, 0));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend,
GetDateTimeMS(2018, 6, 15, 11, 0));
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone,
"UTC");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone,
"UTC");
var res = ContentResolver.Insert(calres, eventValues);