我想在 Android 设备日历 App 4.0 中添加事件。如果我在日历 API 中使用 ID=1,则事件成功添加,但如果我使用不同的 ID,则事件不会添加到日历应用程序中。任何建议都是可取的。在此先感谢我使用以下代码
long ids = -1;
long startMillis = 0;
long endMillis = 0;
Calendar beginTime = Calendar.getInstance();
//beginTime.set(2013, 10, 29, 5,40);
startMillis = beginTime.getTimeInMillis();
Calendar endTime = Calendar.getInstance();
// endTime.set(2013, 10, 30, 4, 20);
endMillis= endTime.getTimeInMillis();
Calendar cal = Calendar.getInstance();
// Insert Event
cr=getContentResolver();
ContentValues values = new ContentValues();
values.put(CalendarContract.Events.CALENDAR_ID, eventId);
values.put(CalendarContract.Events.TITLE, title);
values.put(CalendarContract.Events.DTSTART, startMillis);
values.put(CalendarContract.Events.DTEND, endMillis+60*60*1000);
//values.put(CalendarContract.Events.STATUS, "null");
TimeZone tz = TimeZone.getDefault();
values.put(CalendarContract.Events.EVENT_TIMEZONE, tz.getID());
Uri uri = cr.insert(
CalendarContract.Events.CONTENT_URI, values);