Scheduled Notifications in Android | by Siva Ganesh Kantamani | Mar, 2022

One-Time Alarm

non-public var alarmMgr: AlarmManager? = nullalarmMgr = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager?
class AlarmReceiver : BroadcastReceiver() 

override enjoyable onReceive(p0: Context?, p1: Intent?)
TODO("Not but applied")

val alarmIntent = Intent(this, AlarmReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(
context,
requestCode,
alarmIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
alarmMgr?.set(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + 60 * 1000,
alarmIntent
)

Repeating Alarm

alarmMgr?.setRepeating(
AlarmManager.RTC_WAKEUP,
SystemClock.elapsedRealtime() + 60 * 1000,,
1000 * 60 * 15,
alarmIntent
)

More Posts