Android-从定期重复的待处理通知中获取剩余时间

时间:2018-07-08 13:12:51

标签: android push-notification kotlin android-pendingintent

我根据用户在应用程序中插入的某些值来设置待处理的通知,如下所示:

val notificationAlarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
            val notificationIntent = Intent(this, ReminderBroadcastReceiver::class.java)
            notificationIntent.putExtra("bytes", bytes)
            val pendingNotificationIntent = PendingIntent.getBroadcast(this, REQUEST_CODE, notificationIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT)

            myCalendar.set(Calendar.HOUR_OF_DAY, 10)
            notificationAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, myCalendar.timeInMillis,
                    NOTIFICATION_OFFSET,
                    pendingNotificationIntent)

由于这是重复的意图,因此我只能计算第一个通知,因此无法计算之后的通知。

如何获取剩余时间,直到再次显示通知?

1 个答案:

答案 0 :(得分:0)

如果您为Calendar实例设置了确切的日期和时间,那么使用通知时间-当前设备时间来计算待处理时间会更容易。

希望这会有所帮助。