1

使用此代码,我的队友正在添加日历事件。这没有问题。日历事件显示在谷歌日历中。

    TimeZone timeZone = TimeZone.getDefault();
        ContentResolver cr = getContentResolver();
        ContentValues values = new ContentValues();
        values.put(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
        values.put(CalendarContract.Events.DTSTART, startInMillis);
        values.put(CalendarContract.Events.DTEND, endInMillis);
        values.put(CalendarContract.Events.TITLE, title);
        values.put(CalendarContract.Events.EVENT_LOCATION, "Raum: " + location);
        values.put(CalendarContract.Events.DESCRIPTION,
                "Dauer der Veranstaltung: " + duration + " min" + "---|---Dozent: "
                        + organizer.trim() + "---|---Course added by UNIDATE---|");
        values.put(CalendarContract.Events.CALENDAR_ID, 1);
        Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, values);
        ContentUris.withAppendedId(uri, id);

但现在我想通过他们的 id 删除这些事件。我用过这段代码(除其他外):

long selectedEventId = 1;
String[] selArgs = new String[]{Long.toString(selectedEventId)};
int deleted = getContentResolver().delete(CalendarContract.Events.CONTENT_URI, Events._ID + " =? ", selArgs);

这行不通。我也尝试添加

values.put(CalendarContract.Events._ID, id);
4

1 回答 1

0

一个简单的解决方案是首先清除日历事件,然后添加相关事件。

清除日历事件可以通过调用这个来完成:

context.getContentResolver().delete(CalendarContract.Events.CONTENT_URI, CalendarContract.Events.CALENDAR_ID + " = ?", new String[]{String.valueOf(calendarId)});
于 2016-04-06T10:07:49.103 回答