나는 인터넷에서 많은 것을 검색하여 많은 예제를 시도했다. 내 응용 프로그램을 통해 일정에 성공적으로 일정을 추가 할 수 있지만이 이벤트를 프로그래밍 방식으로 삭제할 수는 없습니다. 다음은 내가 시도한 샘플로 성공적인 결과를 얻을 수 없다는 것입니다.캘린더에서 안드로이드 방식으로 이벤트 삭제하기
토큰 [1]은 이벤트 ID입니다. 상기의
1)
Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");
Uri eventUri = ContentUris.withAppendedId(eventsUri, Long.parseLong(tokens[1]));
getContentResolver().delete(eventUri, null, null);
2)
ContentResolver cr = FlightOperationsCancelTicketFee.this.getContentResolver();
Uri EVENTS_URI = Uri.parse("content://com.android.calendar/" + "events");
deleteEvent(cr, EVENTS_URI, 1);
private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId)
{
Cursor cursor;
if (android.os.Build.VERSION.SDK_INT <= 7)
{
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "Calendars_id=" + calendarId, null, null);
}
else
{
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + calendarId, null, null);
}
while(cursor.moveToNext())
{
long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
}
cursor.close();
}
3)
ContentResolver cr = getContentResolver();
String calUriString = "content://com.android.calendar/events";
Uri cal=Uri.parse(calUriString);
String[] EVENT_PROJECTION=new String[]{"calendar_id","title","dtstart","_id"};
Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");
Uri eventUri =ContentUris.withAppendedId(eventsUri, Long.parseLong(tokens[1]));
String reminderUriString = "content://com.android.calendar/reminders";
Uri remUri =Uri.parse(reminderUriString);
cr.delete(remUri, "event_id="+Commons.event_id, null);
cr.delete(eventUri, null, null);
4)
Uri eventsUri = Uri.parse(getCalendarUriBase()+"events");
Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, Long.parseLong(tokens[1]));
getContentResolver().delete(eventUri, null, null);
것도 작동하지 않는다. 도움이 필요해. 고맙습니다. 편집 : 올바른 컨텍스트를 보낼 수 없다고 생각합니다. 공유 환경 설정을 통해 컨텍스트를 유지할 수있는 방법이 있습니까? 그러나 String 및 Int 값만 유지합니다. 이런 식으로 할 수있는 또 다른 방법이 있습니까? http://developer.android.com/guide/topics/providers/calendar-provider.html
하지만 당신은 기본적으로 책에 의해 그 일을 (1) :