0

关于将事件添加到日历中,我有一个小问题。我正在尝试设置实际的事件开始日期,例如 2013/09/25,但是当日历打开时,它会显示错误的开始日期事件 2015/09/02。PLZ帮助

Intent intent = new Intent(Intent.ACTION_INSERT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra(Events.TITLE, "Learn Android");
        intent.putExtra(Events.EVENT_LOCATION, "xyz");
        intent.putExtra(Events.DESCRIPTION, "xyz");
        calDate1 = new GregorianCalendar(2013,
                    9, 25, 12, 00,
                    00);
            intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                    calDate1.getTimeInMillis());
            intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                    calDate1.getTimeInMillis());

                    intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

        intent.putExtra(Events.RRULE,
                "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");

        intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
        intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
        startActivity(intent);

//------------------------------------日历中的结果

        from 02/09/2015
        to 02/09/2015
4

1 回答 1

0

我认为您的日历实例有问题

试试这个代码。

public static void setCalenderEevent(Context context, Calendar cal,
            String title) throws Exception {
        // Calendar cal = Calendar.getInstance();
        Intent intent = new Intent(Intent.ACTION_EDIT);
        intent.setType("vnd.android.cursor.item/event");
        intent.putExtra("beginTime", cal.getTimeInMillis());
        intent.putExtra("allDay", true);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000);
        intent.putExtra("title", title);
        context.startActivity(intent);
    }
于 2013-08-29T06:54:07.297 回答