2014-09-13 94 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()); 
相关问题