gpt4 book ai didi

android - 将每周事件添加到日历

转载 作者:IT老高 更新时间:2023-10-28 23:25:05 35 4
gpt4 key购买 nike

我想向原生 Calendar 添加一个事件,我想在每个 Tuesday 重复这个事件,直到 2015 年 12 月 31 日:

btnWeekly.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();

Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.setType("vnd.android.cursor.item/event")
.putExtra(Events.TITLE, "Tuesdays")
.putExtra(Events.DESCRIPTION, "Tuesday Specials")
.putExtra(Events.EVENT_LOCATION, "Lixious Bench")
.putExtra(Events.RRULE, "FREQ=WEEKLY;BYDAY=Tu;UNTIL=20151231")
.putExtra(Events.DTSTART, calendar.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
.putExtra(CalendarContract.Events.HAS_ALARM, 1)
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
startActivity(intent);
}
}

问题:在日历中它为每个 Thursday 显示此事件,而我在我的代码中使用了“tu

还有一件事,如果我还想为这个事件提供持续时间,例如:从下午 6:00 到晚上 9:00

最佳答案

你说它显示周四重复,但我得到的是周四的开始日,每周二重复。所以我很确定 RRULE 部分是正确的。

我认为您所要做的就是使用日历设置实际的开始和结束时间以获得正确的毫秒数,然后使用“beginTime”而不是“dtstart”和“endTime”而不是“dtend”。

@Override
public void onClick(View v) {

// If you want the start times to show up, you have to set them
Calendar calendar = Calendar.getInstance();

// Here we set a start time of Tuesday the 17th, 6pm
calendar.set(2015, Calendar.MARCH, 17, 18, 0, 0);
calendar.setTimeZone(TimeZone.getDefault());

long start = calendar.getTimeInMillis();
// add three hours in milliseconds to get end time of 9pm
long end = calendar.getTimeInMillis() + 3 * 60 * 60 * 1000;

Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.setType("vnd.android.cursor.item/event")
.putExtra(Events.TITLE, "Tuesdays")
.putExtra(Events.DESCRIPTION, "Tuesday Specials")
.putExtra(Events.EVENT_LOCATION, "Lixious Bench")
.putExtra(Events.RRULE, "FREQ=WEEKLY;BYDAY=TU;UNTIL=20150428")

// to specify start time use "beginTime" instead of "dtstart"
//.putExtra(Events.DTSTART, calendar.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end)

// if you want to go from 6pm to 9pm, don't specify all day
//.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
.putExtra(CalendarContract.Events.HAS_ALARM, 1)
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

startActivity(intent);
}

关于android - 将每周事件添加到日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28871921/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com