val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
Log.e("TAG", "$hour : ${minute+1}: ", )
val intent:Intent = Intent(this,MyReceiver::class.java)
intent.putExtra("ALARM_TITLE","DRINK")
intent.putExtra("ALARM_TIME","$hour : ${minute+1}")
val calendar: Calendar = Calendar.getInstance()
calendar.timeInMillis = System.currentTimeMillis()
calendar.set(Calendar.HOUR_OF_DAY,hour)
calendar.set(Calendar.MINUTE,minute+1)
calendar.set(Calendar.SECOND,0)
val pendingIntent:PendingIntent = PendingIntent.getBroadcast(
this,
0,
intent,
PendingIntent.FLAG_MUTABLE
)
alarmManager.setRepeating(
AlarmManager.RTC_WAKEUP,
calendar.timeInMillis,
AlarmManager.INTERVAL_DAY,
pendingIntent,
)
When I used setExact(), I received the notification at the exact specified time. However, when I switched to setRepeating(), the notification was delayed by 10 minutes, for instance, when I set the alarm for 10:01 PM, the notification arrived at 10:11 PM.
Please note that I require the alarms to be repeated daily as a reminder.
From the documentation for
setRepeating():In short, you cannot set exact repeating alarms since Android KitKat. Calling
setRepeating()would have the same effect as callingsetInexactRepeating().However, you still have other options. As suggested in the documentation, you can set a one-time exact alarm for when you want it to first go off, and when it fires, you would set it up again with the same time value.