2011-12-21 3 views
4

Nexus S에서 API가 7 인 APP를 개발할 때 내 캘린더에서 새 일정을 만드는 데 문제가 없었습니다. 문제는 내가 안드로이드 ICS 4.0 내 넥서스 S를 업데이트 할 때 온Android 4.0의 캘린더 위치는 어느 것입니까?

cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null); 

:

는 내 휴대 전화에 달력의 위치를 ​​얻기 위해 그 코드를 사용했다. 코드를 변경하지 않고 실수를했습니다. 로그 캣에 나는 읽을 수 :

  • 이러한 열 : 표시 이름을 물론 커서의 dB =/데이터/데이터/com.android.providers.calendar/데이터베이스/calendar.db에게

입니다 없는. 캘린더 데이터베이스가 변경 될 수 있습니까? 당신이 검토 할 수 있도록

답변

3

달력 공급자 4.0을 안드로이드 새로운) 그래서, 나는 안드로이드 4.0

덕분에 API 7 응용 프로그램을 개발하는 새로운 캘린더 이벤트를 만드는 방법을 알고 싶습니다 문서 : 이전 프로 요에 버전

http://developer.android.com/guide/topics/providers/calendar-provider.html

, 전 달력이 content://calendar/calendars에있는 것을 알고 있지만, 그 이후 변경된.

+0

당신이 맞았습니다. 감사합니다;) 이벤트를 특정 캘린더에 추가하는 코드를 작성하려고합니다. 사실은 달력 테이블의 열 이름이 변경되었습니다. – ElChencho

+0

내가 할 수있는 어떤 방식 으로든 도와 줘서 기뻐. –

5

Android 4.0에서는 캘린더가 Android 2.3과 동일한 Uri에 있습니다. 그래서 나는 다른 사람들이 같은 문제를 겪을 경우에 대비하여 코드를 첨부합니다.

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


    final ContentResolver cr = ctx.getContentResolver(); 
    Cursor cursor ; 

    cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id","calendar_displayName" }, null, null, null); 

    /*if (Integer.parseInt(Build.VERSION.SDK) == 8) 
     cursor = cr.query(Uri.parse("content://com.android.calendar/calendars"), new String[]{ "_id", "displayname" }, null, null, null); 
    */ 

    //Get all the calendar ids and name available in the phone 
    if (cursor.moveToFirst()) { 
     final String[] calNames = new String[cursor.getCount()]; 
     final int[] calIds = new int[cursor.getCount()]; 
     for (int i = 0; i < calNames.length; i++) { 
      calIds[i] = cursor.getInt(0); 
      calNames[i] = cursor.getString(1); 
      cursor.moveToNext(); 
     } 

     //Creation of a new event in calendar whose position is 0 on the phone 
     ContentValues cv = new ContentValues(); 
     cv.put("calendar_id", calIds[0]); 
     cv.put("title", title); 
     cv.put("dtstart", dtstart); 
     cv.put("dtend", dtend); 
     cv.put("eventTimezone","Spain"); 
     cv.put("description", comment); 

     //Insertion on the events of the calendar 
     cr.insert(Uri.parse("content://com.android.calendar/events"), cv); 

     /*Uri newEvent ; 
     if (Integer.parseInt(Build.VERSION.SDK) == 8) 
      newEvent = cr.insert(Uri.parse("content://com.android.calendar/events"), cv); 
     */ 

     finish(); 

    } 
    cursor.close(); 

} 

존은 전에 말한대로 모든 정보가 http://developer.android.com/guide/topics/providers/calendar-provider.html입니다.

관련 문제