2012-04-15 8 views
0

캘린더에 새 이벤트를 추가하려고합니다 (최소 sdk 버전은 2.2 임).캘린더에 새 이벤트를 삽입하는 중 오류가 발생했습니다.

ContentValues event = new ContentValues(); 

event.put("calendar_id", 2); 
event.put("title", "mytitle"); 
event.put("description", "desc"); 
event.put("eventLocation", "loc"); 
event.put("eventTimezone", Calendar.getInstance().getTimeZone().getDisplayName()); 

long startTime = System.currentTimeMillis() + 1000 * 60 * 60; 
Long duration = 1000L * 60 * 30; 

event.put("dtstart", startTime); 
event.put("duration", duration); 

Uri eventsUri = Uri.parse("content://com.android.calendar/events"); 
Uri insertedUri = getContentResolver().insert(eventsUri, event); 

그러나 insertedUri는 항상 null입니다 : 내가 지금까지 가지고있는 코드는
.
또한 내 로그 캣에서 그 라인을 볼 수

Failed to find provider info for calendar 

누군가가 나를 도와 드릴까요?
감사합니다.

답변

0

내 대답은 here입니다.
감사

0

안드로이드에는 기본 캘린더가 없습니다. 따라서 항상 공급자를 찾지 못합니다. 따라서 이전에 공개 API가 없었던 것입니다. ex, google 캘린더 용 캘린더 응용 프로그램을 설치해야합니다. 다른 피곤한 파티 앱의 경우 api를 실행합니다.

+0

하지만 난 내 장치에있다. 왜 아직도 아무것도 추가 할 수 없습니까? – Royi

+0

Google 캘린더 – Akhil

+0

을 사용하는 경우 https://developers.google.com/google-apps/calendar/ API를 사용하는 것이 더 좋습니다. 기기가 오프라인 인 경우 이벤트를 추가 할 수있는 방법이 있습니까? – Royi

0

당신이 시도 할 수 있습니다,

public static void addToCalendar(Context ctx, final String title, 
      final long dtstart, final long dtend, final String location) { 

     Intent intent = new Intent(Intent.ACTION_EDIT); 
     intent.setType("vnd.android.cursor.item/event"); 
     intent.putExtra("beginTime", dtstart); 
     intent.putExtra("allDay", false); 
     intent.putExtra("rrule", "FREQ=YEARLY"); 
     intent.putExtra("endTime", dtend); 
     intent.putExtra("title", title); 
     intent.putExtra("eventLocation", location); 
     ctx.startActivity(intent); 
    } 
관련 문제