我正在显示一个TimePicker,我希望在同一天触发警报,但奇怪的是,它会在一天后被调用,除非用户选择的小时已经过去,在这种情况下警报立即触发,你能帮我弄清楚发生了什么吗?
startingHour = timePickerStartingHour.getCurrentHour();
startingMinute = timePickerStartingHour.getCurrentMinute();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, startingMinute);
cal.set(Calendar.HOUR, startingHour);
Intent intent = new Intent(getActivity(), NotificationBroadcast.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 100000+i, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.setExact(AlarmManager.RTC, cal.getTimeInMillis(), pendingIntent);
答案 0 :(得分:0)
如果有人碰到这个问题,请将Calendar.HOUR
替换为Calendar.HOUR_OF_DAY
,它对我有效,为mgcaguioa提供道具