gpt4 book ai didi

android - 如何删除日历条目?

转载 作者:太空狗 更新时间:2023-10-29 15:49:41 33 4
gpt4 key购买 nike

我正在尝试实现我的第一个 android 程序。它应该写日历条目(我知道,这不是开始编程 Andorid 的最佳任务)。

我试过:

Uri CALENDAR_URI = Uri.parse("content://calendar/events");
ContentResolver cr = getContentResolver();
cr.delete(CALENDAR_URI, null, null); // Delete all
cr.delete(CALENDAR_URI, "calendar_id=1", null); // Delete all in default calendar
cr.delete(CALENDAR_URI, "_id=1", null); // Delete specific entry

没有任何效果。我总是收到“无法删除该 URL”的提示。

插入日历项很简单:

ContentValues values = new ContentValues();
values.put("calendar_id", 1);
values.put("title", this.title);
values.put("allDay", this.allDay);
values.put("dtstart", this.dtstart.toMillis(false));
values.put("dtend", this.dtend.toMillis(false));
values.put("description", this.description);
values.put("eventLocation", this.eventLocation);
values.put("visibility", this.visibility);
values.put("hasAlarm", this.hasAlarm);

cr.insert(CALENDAR_URI, values);

根据我访问日历的插入方法。

谢谢,亚瑟!

最佳答案

好吧,有一件事我没试过:

Uri CALENDAR_URI = Uri.parse("content://calendar/events");
int id = 1; // calendar entry ID
Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);
cr.delete(uri, null, null);

这就是我所缺少的:

Uri uri = ContentUris.withAppendedId(CALENDAR_URI, id);

应该指向 content://calendar/events/1

现在我的日历是空的:-)

关于android - 如何删除日历条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1472382/

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