我有特定要求创建将在特定日期发生的日历事件。这不是每周,每月,每年都会发生的情况,但它可能会持续13天,14天,15天等。我有哪些日期会发生,但没有设定经常性日期。下面是我的代码
ContentValues calEvent = new ContentValues();
calEvent.put(CalendarContract.Events.CALENDAR_ID, 1);
calEvent.put(CalendarContract.Events.TITLE, title);
calEvent.put(CalendarContract.Events.DTSTART, d.getTime());
calEvent.put(CalendarContract.Events.DTEND, d.getTime()
+ (2 * 60 * 60 * 1000));
calEvent.put(CalendarContract.Events.HAS_ALARM, 1);
calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone
.getDefault().getID());
calEvent.put(CalendarContract.Events.EVENT_LOCATION, location);
calEvent.put(CalendarContract.Events.DESCRIPTION, description);
calEvent.put(CalendarContract.Events.RDATE, sdf1.format(d)
+ "T033000Z");
// calEvent.put(CalendarContract.Reminders.RRULE, value);
Uri uri = contentResolver.insert(
CalendarContract.Events.CONTENT_URI, calEvent);
// The returned Uri contains the content-retriever URI for the
// newly-inserted event, including its id
int id = Integer.parseInt(uri.getLastPathSegment());
// Toast.makeText(ctx, "Created Calendar Event " + id,
// Toast.LENGTH_SHORT).show();
eventId = eventId + (eventId.equalsIgnoreCase("") ? id : "," + id);
ContentValues calReminder = new ContentValues();
calReminder.put(CalendarContract.Reminders.MINUTES, minutes);
calReminder.put(CalendarContract.Reminders.EVENT_ID, id);
// calReminder.put(CalendarContract.Reminders.HAS_ALARM, 1);
calReminder.put(Reminders.METHOD, Reminders.METHOD_ALERT);
Uri uri1 = contentResolver.insert(
CalendarContract.Reminders.CONTENT_URI, calReminder);
// The returned Uri contains the content-retriever URI for the
// newly-inserted event, including its id
int id1 = Integer.parseInt(uri1.getLastPathSegment());
// Toast.makeText(ctx, "Created Calendar Reminder " + id1,
// Toast.LENGTH_SHORT).show();
reminderId = reminderId
+ (reminderId.equalsIgnoreCase("") ? id1 : "," + id1);
当我使用带有逗号分隔的日期值的RDATE时,因为有startdate&提供enddate,事件创建到startdate和amp;之间的所有日期。结束日期。
答案 0 :(得分:1)
Intent service_intent = new Intent(your application context,
your class.class);
PendingIntent pintent = PendingIntent.getService(
your application context, 0, service_intent, 0);
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
// for 30 mint 60*60*1000
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), APP_DAY_FOR_SERVICE
* APP_HOUR_FOR_SERVICE
* APP_MINUT_FOR_SERVICE
* APP_SECOND_FOR_SERVICE * 1000,
pintent);
在此代码中,24小时后会调用一个事件,所以如果你将APP_DAY_FOR_SERVICE改为2,那么48小时之后一个事件就是虎,所以如果你想在特定的日子之后调用事件,比如你从日历中选择日期,那么那天就开始了当天,将答案放在APP_DAY_FOR_SERVICE,即
APP_DAY_FOR_SERVICE APP_HOUR_FOR_SERVICE APP_MINUT_FOR_SERVICE这些都是整数,如果您有任何查询,请随时询问