2012-10-22 6 views
0

모든 캘린더 항목을 삭제하고 싶습니다. 캘린더 항목 가져 오기에이 쿼리를 사용합니다.캘린더 항목 삭제

Uri uri = Uri.parse("content://com.android.calendar/events"); 
cursor = context.getContentResolver().query(uri, null, null,null, null); 

그러나 커서는 매번 null을 반환합니다. 나는 또한 그것을 확인했다 Uri uri = Uri.parse("content://calendar/events"); 그러나 결과는 같다.

도와주세요.

미리 감사드립니다.

+0

타겟을 API 레벨은 무엇입니까? (캘린더 API는 API 레벨 14/Android 4.0 이전에는 표준화되지 않았습니다.) – Stefan

+0

타겟팅 된 API는 API 레벨 8 이상입니다. –

답변

0

//이 REQ android:minSdkVersion="7"

public void deleteAllCalendar(){ 
     Log.i(TAG, "In deleteAllCalendar()"); 
     String strUriEvents = "content://calendar/events"; 
     Uri uri_calendar = Uri.parse(strUriEvents); 
     String str_column_name = "_id"; 
     String[] projection = {str_column_name}; 
     int columnIndex = 0; 
     String str_id = ""; 
     Vector<String> vector_id = new Vector<String>(); 
     int delRow = 0; 
     String where = ""; 
     try { 
      Cursor cursor = cr.query(uri_calendar, projection, null, null, null); 
      if(cursor.moveToFirst()){ 
       do{ 
        columnIndex = cursor.getColumnIndex(str_column_name); 
        str_id = cursor.getString(columnIndex); 
        vector_id.add(str_id); 
       }while(cursor.moveToNext()); 
      } 
      cursor.close(); 
      for(int i=0; i<vector_id.size(); i++){ 
       str_id = vector_id.get(i); 
       where = str_column_name+"="+str_id; 
       delRow = cr.delete(uri_calendar, where, null); 
       Log.i(TAG, "deleteAllCalendar(),delRow:"+delRow); 
      } 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      Log.e(TAG, "deleteAllCalendar(),Exception"); 
      e.printStackTrace(); 
     } 
     Log.i(TAG, "Out deleteAllCalendar()"); 
    } 
+0

또한 커서에 null을 제공합니다. –

+0

@ unflagged.destination did U READ_CALENDAR 및 \t WRITE_CALENDAR \t 응용 프로그램이 사용자의 일정 데이터를 쓸 수는 있지만 읽지는 못하게합니다. manifest.xml의 사용 권한 –

+0

예, 커서의 결과는 동일합니다. –

0

문제 시도는 URI의 일환으로 달력 기관이다. API 레벨 14 이전에는 표준화되지 않았습니다. 레벨 8 이상을 타겟팅하는 경우 com.android.calendar은 Google 코드에서 제안되었지만 휴대 전화 제조업체는 다른 권한을 사용할 수 있습니다. API 8 이전에는 권한이 calendar (이전 답변에서 사용 된 것)입니다.

사용자의 캘린더에 쓸 수있는 권한을 부여해야합니다.

이벤트를 삭제할 때 확장 속성, 미리 알림 및 경고도 삭제해야합니다. 여기에 자신의 경로는 다음과 같습니다 API 레벨 14으로

private static final String calendarPath = "calendars"; 
private static final String eventsPath = "events"; 
private static final String remindersPath = "reminders"; 
private static final String calAlertsPath = "calendar_alerts"; 
private static final String eventsExtPropPath = "extendedproperties"; 

이 표준화되고 당신은 CalendarContract에서 URI를 얻을 수 있습니다 :

CalendarContract.Calendars.CONTENT_URI; 
    CalendarContract.Events.CONTENT_URI; 
    CalendarContract.Reminders.CONTENT_URI; 
    CalendarContract.CalendarAlerts.CONTENT_URI; 
    CalendarContract.ExtendedProperties.CONTENT_URI; 
+0

예 URI를 모두 확인했지만 항상 커서가 null을 나타냅니다 –

+0

언급 된 권한을 확인 했습니까? – Stefan

+0

예. 그러나 커서는 null을 반환합니다. –