android - 使用 Intent 在日历中为多天设置相同的时间间隔

标签 android

我目前正在使用此代码向用户设备中的日历添加事件:

    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/

相关文章:

Android 数据库助手单例和同步

java - Android Java 源代码中的歧义

javascript - ionic 运行 android 不工作

android - ActionMode.Callback 的实现

android - 如何在android studio中将位图上传到firebase

android - 是否可以在 Activity 中开始 Activity ?如何?

java - 如何通过gcm发送自定义消息并得到其响应?

android - android PDF 查看器是否将 PDF 转换为图像?

android - 为 Pre-Lollipop 设备创建 Circular Reveal

java - android 以编程方式更改imageview