所以基本上我有这个代码,时间返回24小时的时间,并重复每天的警报。AlarmManager超过当天设置的时间,setRepeating
public setAlarm(String time, Context context){
String[] strTime;
strTime = time.split(":");
int hour, min, sec;
//set when to alarm
hour = Integer.valueOf(strTime[0]);
min = Integer.valueOf(strTime[1]);
sec = 0;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, min);
cal.set(Calendar.SECOND, sec);
//Create a new PendingIntent and add it to the AlarmManager
Intent intent = new Intent(context, AlarmReceiverActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 19248, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
无论如何,问题是当我在9点10分设置闹钟9点时,闹钟将熄灭。为什么?如果它超过系统时间,我希望它不会报警。防爆。设置报警上午9点,而系统时间为上午9:10
AlarmManager.INTERVAL_DAY + 1 - 为什么你添加+1? –
因为“如果警报延迟(通过系统睡眠,例如,对于非_WAKEUP警报类型),将尽快发送一个跳过的重复。之后,将来的警报将按照原始日程安排发送;它们会不随时间漂移。例如,如果您在每小时的顶部设置了重复闹钟,但手机在7:45至8:45之间睡着了,手机一旦唤醒就会发出闹钟,然后下一次闹钟将以9:00。 “所以,如果你在同一天设置警报,警报就会启动 – FeanDoe