问题描述
我想在开始时间前7天和1小时之前的不同提醒时间向日历添加活动
I want to add an event to calender with different reminder time 7 days before and 1 hour before the start time
这是我正在做的
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);
任何人都可以告诉我如何添加提醒
Can anyone tell me how to add reminder
谢谢你提前。
推荐答案
如果你想添加一个事件到日历,你应该调用日历应用程序与值设置。由于您要添加两个事件,您必须调用日历应用程序两次并设置不同的值。
If you want to add an event to a calendar, you should call the Calendar app with the values set. Since you want to add two events, you have to call the Calendar app twice and set different values to both.
向日历添加事件的代码
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());
Now since you want to add two reminders, call this method twice with different parameters for date at intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, date());
这篇关于在日历应用程序中为该事件添加事件和多个提醒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!