添加周刊事件日历 [英] Add Weekly Event to Calendar

查看:219
本文介绍了添加周刊事件日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个事件添加到本地日历,在这里,我想对每一个重复此事件星期二直到 2015年12月31号

I would like to add an event to native Calendar, here i want to repeat this event on every Tuesday until 31 December 2015:

btnWeekly.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                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);
                }            

            }

        });

问题:在日历它显示出本次活动的每一个周四,而我用

Problem: In Calendar it showing this event for every Thursday, whereas i have used "tu" in my code

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

And one more thing what if i also want to give time duration for this event like: from 6:00 pm to 9:00 pm only.

推荐答案

您说,这表明重复周四,但我得到的是周四的开始一天的重复每星期二。所以我pretty的确认RRULE部分是正确的。

You said it showed repeating for Thursday, but what I got was a start day of Thursday with a repeat every Tuesday. So I'm pretty sure the RRULE part is right.

我认为,所有你需要做的就是设置实际开始和结束时间与日历,以获得正确毫秒,那么用户BEGINTIME而不是DTSTART和endTime的,而不是DTEND。

I think all you have to do is set the actual start and end times with Calendar to get the right milliseconds, then user "beginTime" instead of "dtstart" and "endTime" instead of "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);
     }

  });

这篇关于添加周刊事件日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆