带有UTC时间的CalendarContract事件创建问题

时间:2018-09-15 16:17:16

标签: java android google-calendar-api calendarcontract

当我尝试使用下面的代码创建事件时,它将事件添加到日历中,但是直到我通过Google Calendar app重新加载日历后,它才真正显示具有UTC时区的事件:

ContentResolver cr = context.getContentResolver();
ContentValues values = new ContentValues();

values.put(CalendarContract.Events.ALL_DAY, true);
values.put(CalendarContract.Events.DTSTART, startTime);  //UTC LONG
values.put(CalendarContract.Events.DTEND, endTime + DateUtils.DAY_IN_MILLIS);  // UTC Long
values.put(CalendarContract.Events.EVENT_TIMEZONE, Time.TIMEZONE_UTC);
values.put(CalendarContract.Events.TITLE, title);
values.put(CalendarContract.Events.EVENT_LOCATION, loc);
values.put(CalendarContract.Events.DESCRIPTION, desc);
values.put(CalendarContract.Events.CALENDAR_ID, Long.parseLong(calendarId));
values.put(CalendarContract.Events.EVENT_COLOR, color);
values.put(CalendarContract.Events.HAS_ALARM, true);
values.put(CalendarContract.Events.HAS_ATTENDEE_DATA, true);

cr.insert(CalendarContract.Events.CONTENT_URI.buildUpon()
     .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
     .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, acc)
     .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, typ)
     .build(), values);

以下是当地时区为伦敦的事件的输出:

**Created By GC App:**
     TITLE: by gc app,
     START_DAY: 2458378,
     END_DAY: 2458380,
     START_MINUTE: 0,
     END_MINUTE: 1440, 
     EVENT_TIMEZONE: UTC,
     START: 1537056000000,
     END: 1537315200000

**Created By CalendarContract code:**
     TITLE: by calendarcontract,
     START_DAY: 2458378,
     END_DAY: 2458381,      // different end day
     START_MINUTE: 60,      // different start minute
     END_MINUTE: 60,        // different end minute
     EVENT_TIMEZONE: UTC,   
     START: 1537056000000,  // same start time
     END: 1537315200000     // same end time

但是当我通过Google calendar app更改设备时区或刷新日历时,它开始正确显示。

0 个答案:

没有答案
相关问题