我目前正在使用此代码向用户设备中的日历添加事件:
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra(CalendarContract.Events.TITLE, mission.company.name);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, mission.service.address);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startCal.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endCal.getTimeInMillis());
intent.putExtra(CalendarContract.Events.ALL_DAY, false);// periodicity
intent.putExtra(CalendarContract.Events.DESCRIPTION,
function.name + "\n\n" + mission.service.address + "\n\n" + mission.service.phone
);
String title = "Choose the calendar you want to save the event to";
Intent chooser = Intent.createChooser(intent, title);
try {
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
} catch (ActivityNotFoundException e) {
Toast.makeText(this, getString(R.string.toast_no_application_found_for_action), Toast.LENGTH_SHORT).show();
}
我的问题是这只会添加一个事件。我遇到过在同一时间间隔(即中午 12:00 - 中午 13:00)需要重复 2-3 天(周一、周二、周三)的情况。我怎样才能改变代码(我想使用 Intent )来完成这个?如果我只是将事件设置为周一中午 12:00 开始,并说它将在周三中午 13:00 结束,那是不好的,因为它会设置一个长事件。
有什么想法吗?
最佳答案
您可以向您的 Intent 添加一个新的额外内容,以将 CalendarContract.Events.RRULE 字段设置为值“FREQ=DAILY;COUNT=x”(其中 x 是重复事件的天数)。
关于android - 使用 Intent 在日历中为多天设置相同的时间间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42324625/