使用Intent

时间:2017-02-19 07:09:21

标签: 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天(周一,周二,周三)。如何更改代码(我想使用Intents)来完成此任务?如果我只是在星期一中午12点设置活动的开始,并说它将在星期三下午13:00结束,这是不好的,因为它将设置一个长事件。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您可以在Intent中添加一个新的额外内容,将CalendarContract.Events.RRULE字段设置为值" FREQ = DAILY; COUNT = x"(其中x是周期性事件的天数) )。