I'm displaying a TimePicker and I want an Alarm to get triggered on that time in the same day, but weirdly, it's getting called a day after, unless the hour the user picks has already passed, in that case the Alarm triggers immediately, can you help me figuring out what's happening?
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);
如果有人碰到这个问题,用Calendar.HOUR
替换Calendar.HOUR_OF_DAY
,它对我有效,为mgcaguioa道具
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.