2011-04-13 53 views
0

我是新來的android開發世界。我想將一個事件添加到我的本機日曆中,我可以成功地看到該操作,但是當我轉到日曆時,我看不到這一點。我的代碼是Android 2.2 - 爲什麼我看不到我添加到日曆中的事件?

String [] projection = new String [] {「_id」,「name」}; Uri calendar = Uri.parse(「content://com.android.calendar/calendars」);

  Cursor c = managedQuery(calendars, projection, "selected=1", null, null); 

      if(c.moveToFirst()){ 
       String calName; 
       String calID; 
       int nameColumn = c.getColumnIndex("name"); 
       int idColumn = c.getColumnIndex("_id"); 
       calName = c.getString(nameColumn); 
       calID = c.getString(idColumn); 

       Time start = new Time("20110416T090000"); 
       Time end = new Time("20110416T100000"); 
       ContentValues values = new ContentValues(); 
       values.put("calendar_id", calID); 
       values.put("title", "Event Title"); 
       values.put("description", "test d"); 
       values.put("eventLocation", "Melbourne"); 
       values.put("dtstart", start.toMillis(true)); 
       values.put("dtend", end.toMillis(true)); 
       values.put("allDay", 0); 
       values.put("eventStatus", 1); 
       values.put("transparency", 0); 
       values.put("visibility", 0); 
       values.put("hasAlarm", 1); 
       Uri events = Uri.parse("content://com.android.calendar/events"); 
       Uri result = getContentResolver().insert(events, values); 

我使用摩托羅拉單元。有人能指出我爲什麼失敗嗎?非常感謝。

回答

0

我已經使用了以下ContentValues在我自己的項目,並取得了成功:

  ContentValues cv = new ContentValues(); 
      cv.put("calendar_id", calendarid);   
      cv.put("title", "sometitle"); 
      cv.put("dtstart", ""+calendarfrom.getTimeInMillis()); 
      cv.put("dtend", ""+calendarto.getTimeInMillis()); 
      cv.put("hasAlarm", 0); 

      Uri newevent = getContentResolver().insert(Uri.parse("content://calendar/events"), cv); 

我懷疑你是提供導致失敗的contentvalues之一。首先嚐試我的簡化示例。

+0

謝謝,我得到了根源。這是我的時間設置的格式。現在,它的工作。 – Dik 2011-04-14 09:35:16

相關問題