2011-04-13 5 views
0

나는 안드로이드 개발 세계에 처음이다. 내 기본 캘린더에 하나의 일정을 추가하고 싶습니다. 작업을 성공적으로 볼 수 있지만 캘린더에 가면 볼 수 없습니다. 내 코드는 다음과 같습니다.Android 2.2 - 캘린더에 추가 한 일정을 볼 수없는 이유가 무엇인가요?

String [] projection = new String [] { "_id", "name"}; Uri calendars = 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); 

나는 Motorola 장치를 사용합니다. 아무도 내가 왜 실패했는지 지적 할 수 있습니까? 고마워.

답변

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

관련 문제