java.lang.IllegalArgumentException:事件值必须包含eventTimezone

时间:2014-09-13 13:01:31

标签: android android-emulator android-contentprovider

我正在开发一个需要在android中将事件添加到本机日历的应用程序。 我跟着 : http://www.grokkingandroid.com/androids-calendarcontract-provider/#comment-341407 http://developer.android.com/guide/topics/providers/calendar-provider.html

这是我尝试的addEvent()方法的代码(在第一篇教程中完全相同)

public void addEvents()
    {
        long calId = getCalendarId();
        if (calId == -1) {
            // no calendar account; react meaningfully
            return;
        }
        Log.i(LOGTAG,calId+"");
        Calendar cal = new GregorianCalendar(2012, 11, 14);
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
            cal.set(Calendar.HOUR, 0);
            cal.set(Calendar.MINUTE, 0);
            cal.set(Calendar.SECOND, 0);
            cal.set(Calendar.MILLISECOND, 0);

        long start = cal.getTimeInMillis();
        ContentValues values = new ContentValues();
                    values.put(Events.DTSTART, start);
                    values.put(Events.DTEND, start);
                    values.put(Events.RRULE, 
                          "FREQ=DAILY;COUNT=20;BYDAY=MO,TU,WE,TH,FR;WKST=MO");
                    Log.i(LOGTAG,calId+" before titile");
                    values.put(Events.TITLE, "Some title");
                    values.put(Events.EVENT_LOCATION, "Munster");

                    Log.i(LOGTAG,calId+" cal ID");
                    values.put(Events.CALENDAR_ID, calId);

                Log.i(LOGTAG,calId+" timezone");

                    **values.put(Events.EVENT_TIMEZONE, "Europe/Berlin");**
                    values.put(Events.DESCRIPTION,
                          "The agenda or some description of the event");
 //....
}

此代码提供“ java.lang.IllegalArgumentException:事件值必须包含eventTimezone”

我在谷歌尝试了很多解决方案,但没有什么能解决这个问题..

2 个答案:

答案 0 :(得分:2)

试试这个:

values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());

答案 1 :(得分:0)

最后我找到了解决方案..... values.put(Events.EVENT_TIMEZONE,“Europe / Berlin”);应该换成 values.put(Events.EVENT_TIMEZONE,“UTC / GMT +2:00”);

这是关于我的模拟器实例中使用的格式约定我猜:)