我正在构建一个让用户选择困难的健身房应用程序。难度根据时间设置,用户查看难度后点击健身房姿势。时间将根据困难运行,如果时间用完,将触发警报。但在我的条件下,时间用完后警报不会触发。我已经在清单中添加了接收器 android:name。这是我的代码:
private void saveAlarm(boolean checked) {
if (checked) {
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent;
PendingIntent pendingIntent;
int Hour, Minute;
alarmIntent = new Intent(Setting.this, AlarmNotificationReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);
if (Build.VERSION.SDK_INT >= 23) {
Hour = timePicker.getHour();
Minute = timePicker.getMinute();
} else {
Minute = timePicker.getCurrentMinute();
Hour = timePicker.getCurrentHour();
}
Date dat = new Date();
Calendar cal_alarm = Calendar.getInstance();
Calendar cal_now = Calendar.getInstance();
cal_now.setTime(dat);
cal_alarm.setTime(dat);
cal_alarm.set(Calendar.HOUR_OF_DAY, Hour);
cal_alarm.set(Calendar.MINUTE, Minute);
cal_alarm.set(Calendar.SECOND, 10);
if (cal_alarm.before(cal_now)) {
cal_alarm.add(Calendar.DATE, 1);
}
alarmManager.set(AlarmManager.RTC_WAKEUP, cal_alarm.getTimeInMillis(), pendingIntent);
}
}
慕斯王
相关分类