我尝试使用以下代码在日历中添加事件。它适用于除Nexus 6(OS 6.0.1)之外的所有设备。它在Logcat中显示Log added event: content://com.android.calendar/events/1598
。但是这个事件没有出现在我的日历中。
代码:
private void addEvents() {
ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", "event Name");
values.put("allDay", 0);
values.put("dtstart", myCalendar.getTimeInMillis() + 11*60*1000); // event starts at 11 minutes from now
values.put("dtend", myCalendar.getTimeInMillis()+60*60*1000); // ends 60 minutes from now
values.put("description", "event desc");
values.put("hasAlarm", 1);
values.put(CalendarContract.Events.EVENT_TIMEZONE,TimeZone.getDefault().getID());
ContentResolver resolver=getApplicationContext().getContentResolver();
Uri event = resolver.insert(CalendarContract.Events.CONTENT_URI, values);
Log.d("added event",event.toString());
}