android - 如何修复日历的意图而不是将其添加为全天事件
问题描述
我正在尝试向我的应用程序添加一个按钮,该按钮允许某人将任务添加到他们的日历中。我正在使用 Intent 和 CalendarContract 执行此操作。一切正常,因为它以添加事件状态启动日历应用程序,并且所有信息都在正确的字段中并正确显示。我唯一遇到的问题是
CalendarContract.EXTRA_EVENT_ALL_DAY to true
没有使其默认为全天活动。
我已经尝试将它分成多个 .putExtra 语句,并尝试了单个组件,但这些似乎都没有任何区别。
startActivity(Intent(Intent.ACTION_EDIT)
.setData(CalendarContract.Events.CONTENT_URI)
.setType("vnd.android.cursor.dir/event")
.putExtras(
bundleOf(
CalendarContract.Events.TITLE to assignment.getItemText(),
CalendarContract.Events.DESCRIPTION to "${assignment.beginDate.takeIf { it != null }?.let {
"${getString(R.string.start_date)}: ${it.format("MMM dd, h:mm a")}\n\n"} ?: ""}${getString(R.string.due_date)}: ${assignment.dueDate.format("MMM dd, h:mm a")}\n\n${assignment.getDetailText()}",
// If there is just one time, put it in for both so that the generated event in the calendar app has logical and related start/end times
CalendarContract.EXTRA_EVENT_BEGIN_TIME to (assignment.beginDate?.time ?: assignment.dueDate.time),
CalendarContract.EXTRA_EVENT_END_TIME to assignment.dueDate.time,
CalendarContract.EXTRA_EVENT_ALL_DAY to true
)
)
)
我希望这将允许我添加一个全天选择的事件,但它不会默认为该事件。
我注意到这个问题只发生在谷歌日历上
任何帮助都会非常感谢。
解决方案
这似乎是当前版本的 Android 与 Google 日历集成中的一个错误。希望他们很快会在补丁版本中修复错误。它肯定适用于我测试过的所有其他日历
推荐阅读
- powerbi - 将度量与列中的值进行比较
- c# - System.InvalidCastException:无法将“System.Int32”类型的对象转换为“System.String”类型
- scala - 使用 testcontainers 测试 kafka 和 spark
- python - 试图从“in”语句中返回 True False 值
- office-js - Outlook 插件或 Microsoft Exchange:它可以从电子邮件正文中删除元素吗?
- powerapps - Power Apps 库与使用筛选器的联接
- c++ - C++:如何使用 spdlog 打印自定义类指针?
- python-3.x - 使用 UTF-8 编码抓取请求时不显示日文字符
- java - qemu-system-x86_64.exe 没有响应
- css - 无法在电子邮件模板的内联 CSS 中使用字体