gpt4 book ai didi

android - 删除谷歌日历中的单次事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:30:44 24 4
gpt4 key购买 nike

我想删除重复事件的单次出现。这是我的代码:

private void handleActionDelete(long event, long occurrence) {
final ContentResolver contentResolver = getContentResolver();

Uri.Builder eventsUriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(eventsUriBuilder, Long.MIN_VALUE);
ContentUris.appendId(eventsUriBuilder, Long.MAX_VALUE);
Uri eventsUri = eventsUriBuilder.build();
Cursor cursor;
String[] projection;
projection = new String[]{CalendarContract.Instances.BEGIN};
String selection = "Instances." + CalendarContract.Instances._ID + " = ? AND " + CalendarContract.Instances
.EVENT_ID + " = ?";
String[] selArgs = new String[]{Long.toString(occurrence), Long.toString(event)};
cursor = getContentResolver().query(eventsUri, projection, selection, selArgs, null);
if (cursor == null) {
return;
}
if (cursor.getCount() == 0) {
cursor.close();
return;
}
cursor.moveToFirst();

ContentValues values = new ContentValues();
values.put(CalendarContract.Events.ORIGINAL_INSTANCE_TIME, cursor.getLong(cursor.getColumnIndex
(CalendarContract.Instances.BEGIN)));
values.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CANCELED);
Uri uri = Uri.withAppendedPath(CalendarContract.Events.CONTENT_EXCEPTION_URI, String.valueOf(event));
cursor.close();
try {
contentResolver.insert(uri, values);
} catch (Exception ignored) {
}
}

我已经在 stackoverflow 上检查了所有其他类似的问题,但我没有找到任何解决方案,也许这与我的代码有关,我希望有人可以审查它。

最佳答案

如果您使用 com.google.api.services.calendar.Calendar 我想您已经有了要删除的事件的 id

答案就在 documentation 中和状态(我从文档中复制了确切的 fragment ):

// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName("applicationName").build();

// Delete an event
service.events().delete('primary', "eventId").execute();

关于android - 删除谷歌日历中的单次事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49179563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com