2013-09-25 102 views
1

改变我使用下面的代码的事件添加到压延Android的Google日历时区不CalendarContract

Intent intent = new Intent(Intent.ACTION_INSERT); 
    intent.setType("vnd.android.cursor.item/event"); 
    intent.putExtra(Events.TITLE, "my event title"); 
    intent.putExtra(Events.EVENT_LOCATION, "my city"); 
    intent.putExtra(Events.DESCRIPTION, "description of this event"); 

    intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, dep.getTimeInMillis()); 
    intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, arr.getTimeInMillis());   

    intent.putExtra(CalendarContract.Events.EVENT_TIMEZONE, departureTimeZone); 
    intent.putExtra(CalendarContract.Events.EVENT_END_TIMEZONE, arrivalTimeZone); 

    // Making it private and shown as busy 
    intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE); 
    intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

    CoreApplication.getContext().startActivity(intent); 

的问题是,它拿起时是 一小时比原来的时间我送SHORTER和 时区总是被设置为像“欧洲中部夏令时间GMT + 2”

请帮助设备的时区!!!!!!!!!!!!!!!

回答

0

你应该检查这个链接Calendar Provider intents,它说我们不能把时区作为意图的额外,所以发送事件的beginTimeendTime UTC。

在事件中插入意图的例子中提到,“它使用CalendarContract.EXTRA_EVENT_BEGIN_TIMECalendarContract.EXTRA_EVENT_END_TIM E扩展字段预填充事件的时间的形式。这些时间值必须从时代UTC毫秒。 “

2

有同样的麻烦,但找到了出路。
TimeZone默认设置为设备的时区。要更改此设置并将其设置为特定时区,请使用getRawOffset()属性。
此方法计算当前时间的毫秒数。因此,您可以为指定的timeZone添加毫秒,并将其减去默认的timeZone。

当我试图改变它由于时区 'GMT_ID'

values.put(CalendarContract.Events.DTSTART, startDate.getTime() +TimeZone.getTimeZone(GMT_ID).getRawOffset() -TimeZone.getDefault().getRawOffset()); 

希望这有助于。