Ребята,
AlarmManager не срабатывает на
Android P. Кто сталкивался с проблемой? Я понять не могу почему?
BroadcastReceiver зарегистрирован в манифесте. В
AlarmReceiver просто
NotificationManager с методом
showNotification, который формирует само уведомление.
val calendar = Calendar.getInstance()
calendar.apply { timeInMillis = launch.timestamp * 1000 }
val alarmIntent = Intent(applicationContext, AlarmReceiver::class.java)
alarmIntent.action = "NOTIFICATION_ACTION"
alarmIntent.putExtra(MISSION_NAME, launch.title)
alarmIntent.putExtra(MISSION_DETAIL, "Is launching right now!")
val pendingIntent = PendingIntent.getBroadcast(
applicationContext,
0,
alarmIntent,
PendingIntent.FLAG_UPDATE_CURRENT
)
Log.d("Spacex/Alarm", "Right before set at: ${formatDate(calendar.timeInMillis)}")
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, pendingIntent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, pendingIntent)
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.timeInMillis, pendingIntent)
}