我需要支持Android 2.1及更高版本。我知道 CalendarContract 在 Android 2.1 中不可用,所以我做了以下解决方法。
Intent intent = new Intent(Intent.ACTION_EDIT)
.setType("vnd.android.cursor.item/event")
.putExtra("beginTime", beginTime.getTimeInMillis())
.putExtra("title", title)
.putExtra("description", description)
.putExtra("eventLocation", location)
.putExtra("allDay", allDay)
.putExtra(Intent.EXTRA_EMAIL, email );
if(!allDay) {
intent.putExtra("endTime", endTime.getTimeInMillis());
}
startActivity(intent);
到目前为止,这效果很好。我已经在 2.1 到 4.1 上进行了测试。
我也想添加提醒,但我找不到任何有关如何使用 Intents 执行此操作的文档。有人有例子吗?我想避免向我的清单添加更多写入日历的权限,因此,如果您有需要的建议,我将无法使用它。
如果您检查股票安卓日历源代码,则无法使用意图添加提醒。
取而代之的是,calendar
有一个设置默认提醒的设置。但一些原始设备制造商本可以实施这一点。因此,即使您找到它,它也无法在所有手机上使用。