嗨,我想在这里调试一个问题并且真的很挣扎。
ContentValues eventValues = new ContentValues();
eventValues.Put(CalendarContract.Events.InterfaceConsts.CalendarId, -1);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Title, title);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Description, desc);
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtstart, GetDateTimeMS(year, month, day, starthr, startmin));
eventValues.Put(CalendarContract.Events.InterfaceConsts.Dtend, GetDateTimeMS(year, month, day, stophr, stopmin));
eventValues.Put(CalendarContract.Events.InterfaceConsts.HasAlarm, true);
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "Local");
eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "Local");
// eventValues.Put(CalendarContract.Events.InterfaceConsts.AllowedReminders, true);
var eventUri = ContentResolver.Insert(CalendarContract.Events.ContentUri, eventValues);
long eventID = long.Parse(eventUri.LastPathSegment);
ContentValues reminderValues = new ContentValues();
reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.CalendarId, -1);
reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.EventId, eventID);
reminderValues.Put(
CalendarContract.Reminders.InterfaceConsts.Method,
(int)RemindersMethod.Alert
);
reminderValues.Put(CalendarContract.Reminders.InterfaceConsts.Minutes, 5);
它崩溃了这条线: var eventUri = ContentResolver.Insert(CalendarContract.Events.ContentUri,eventValues);
错误: Java.Lang.IllegalArgumentException:未知的URL内容://com.android.calendar/calendars/-1
我在三星Galaxy Edge G925F上进行测试
答案 0 :(得分:0)
好的答案很简单。
我没有指定合理的CalendarId,大多数机器人的默认值是1或3.我会使用3,因为在某些型号上1是为生日事件保留的。 (除非它是你想要的生日..)
日期格式化程序一直做错了。而不是指定一个月,JSON拉动事件正在删除前导0,因此09只是9.这导致问题所以只是继续并发出一个if语句并明确指定月份。
long GetDateTimeMS(int yr, int month, int day, int hr, int min)
{
Java.Util.Calendar c = Java.Util.Calendar.GetInstance(Java.Util.TimeZone.Default);
c.Set(Java.Util.Calendar.DayOfMonth,day);
c.Set(Java.Util.Calendar.HourOfDay, hr);
c.Set(Java.Util.Calendar.Minute, min);
if (month == 1)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.January);
}
else if (month == 2)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.February);
}
else if (month == 3)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.March);
}
else if (month == 4)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.April);
}
else if (month == 5)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.May);
}
else if (month == 6)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.June);
}
else if (month == 7)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.July);
}
else if (month == 8)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.August);
}
else if (month == 9)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.September);
}
else if (month == 10)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.October);
}
else if (month == 11)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.November);
}
else if (month == 12)
{
c.Set(Java.Util.Calendar.Month, Java.Util.Calendar.December);
}
c.Set(Java.Util.Calendar.Year,yr);
return c.TimeInMillis;
}
我希望能帮助别人摆脱困境。