在日历应用

时间:2015-12-08 09:42:07

标签: android events calendar

我希望在开始时间前7天和开始时间前1小时将不同的提醒时间添加到日历中

这就是我正在做的事情

long timeInMilliseconds = 0;
            String date = selectedEvent.eventDate;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date mDate = null;
            try {
                mDate = sdf.parse(date);
                timeInMilliseconds = mDate.getTime();
                System.out.println("Date in milli :: " + timeInMilliseconds);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            Calendar cal = Calendar.getInstance();
            cal.setTime(mDate);
            cal.set(Calendar.HOUR_OF_DAY, 8);
            cal.set(Calendar.MINUTE, 00);
            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setType("vnd.android.cursor.item/event");
            intent.putExtra("beginTime", cal.getTimeInMillis());
            intent.putExtra("allDay", false);
            // intent.putExtra("rrule", "FREQ=YEARLY");
            cal.add(Calendar.HOUR_OF_DAY, 8);
            intent.putExtra("endTime", cal.getTimeInMillis());
            intent.putExtra("title", selectedEvent.name);
            String body = "";
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Log.d("", "Timzone--" + format.getTimeZone());
            Date convertedDate = new Date();
            try {
                convertedDate = format.parse(selectedEvent.eventDate);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            SimpleDateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy");
            outputFormat.setTimeZone(TimeZone.getDefault());


            body += outputFormat.format(convertedDate) + "\n";
            body += selectedEvent.name + "\n";
            body += selectedEvent.format + "\n";
            body += selectedEvent.remark1 + "\n";
            body += selectedEvent.remark2 + "\n";
            body.replaceAll("null", "");
            intent.putExtra("description", body);
            intent.putExtra(CalendarContract.Events.EVENT_LOCATION, plat);
            intent.putExtra(CalendarContract.Events.HAS_ALARM, 1);
            startActivity(intent);

任何人都可以告诉我如何添加提醒

提前谢谢。

1 个答案:

答案 0 :(得分:0)

如果要将事件添加到日历,则应使用设置的值调用日历应用。由于您要添加两个事件,因此您必须两次调用日历应用程序并为两者设置不同的值。

将事件添加到日历的代码

Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setType("vnd.android.cursor.item/event");
            intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, date());
            intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, false);
            intent.putExtra(CalendarContract.Events.TITLE, title[i]);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);

现在,由于您要添加两个提醒,请使用不同的参数调用此方法两次,以获取intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, date());的日期