2014-09-13 90 views
-1

我正在開發一個應用程序,它需要將事件添加到android中的本機日曆中。 我跟着: http://www.grokkingandroid.com/androids-calendarcontract-provider/#comment-341407 http://developer.android.com/guide/topics/providers/calendar-provider.htmljava.lang.IllegalArgumentException:事件值必須包含eventTimezone

這是的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「

我嘗試了很多在google中找到的解決方案,但沒有什麼能解決這個問題..

回答

0

最後我找到了一個解決方案..... values.put(Events.EVENT_TIMEZONE,「Europe/Berlin」);應改爲 values.put(Events.EVENT_TIMEZONE,「UTC/GMT +2:00」);

這是關於我的模擬器實例使用我猜這是

2

試試這個格式約定:

values.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID()); 
相關問題