如何设置一定天数的定期闹钟,例如每27天或15天
switch (reminder.getRepeatType()) {
case Reminder.HOURLY:
calendar.add(Calendar.HOUR, reminder.getInterval());
break;
case Reminder.DAILY:
calendar.add(Calendar.DATE, reminder.getInterval());
break;
case Reminder.WEEKLY:
calendar.add(Calendar.WEEK_OF_YEAR, reminder.getInterval());
break;
case Reminder.MONTHLY:
calendar.add(Calendar.MONTH, reminder.getInterval());
break;
case Reminder.YEARLY:
calendar.add(Calendar.YEAR, reminder.getInterval());
break;
答案 0 :(得分:0)
The API is
// Hopefully your alarm will have a lower frequency than this!
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
Details :
https://developer.android.com/training/scheduling/alarms.html
答案 1 :(得分:0)
这是一个触发重复broadcastReceiver的简单示例代码:
public static void setRepeaterAlarm(Context context, Class<?> cls, long afterTimeMillis, long intervalTimeMillis) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, cls);
PendingIntent pendIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
long triggerAtTime = SystemClock.elapsedRealtime() + afterTimeMillis;
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAtTime, intervalTimeMillis, pendIntent);
}