0

apologies if this is a simple answer that I do not know. I am trying to set an alarm with alarm managers setAlarmClock(). My alarm goes off on the proper time, but it is random throughout the minute I set it at. For example, if I set it at 8:30, it will go off at 8:30, but it is random throughout the minute that it goes off. How do I get it to go off right as it turns 8:30.

val calendar: Calendar = Calendar.getInstance().apply {
            timeInMillis = System.currentTimeMillis()
            set(Calendar.HOUR_OF_DAY, 20)
            set(Calendar.MINUTE, 31)
        }


var trig: AlarmManager.AlarmClockInfo = 
    AlarmManager.AlarmClockInfo(calendar.timeInMillis, alarmIntent)
        alarmMgr?.setAlarmClock(
            trig,
            alarmIntent
        )
auotive
  • 179
  • 1
  • 9

1 Answers1

0

I needed to set the calender seconds to zero to get it to work right at the start of the minute.

            set(Calendar.HOUR_OF_DAY, 16)
            set(Calendar.MINUTE, 24)
            set(Calendar.SECOND, 0)
auotive
  • 179
  • 1
  • 9