【问题标题】:Android - get remaining time from a pending notification that is repeating periodicallyAndroid - 从定期重复的待处理通知中获取剩余时间
【发布时间】:2018-07-08 13:12:50
【问题描述】:

我根据用户在应用中插入的一些值设置了一个待处理的通知,如下所示:

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)

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

我如何才能获得通知将再次显示的剩余时间?

【问题讨论】:

    标签: android push-notification kotlin android-pendingintent


    【解决方案1】:

    如果您为日历实例设置准确的日期和时间,那么使用通知时间 - 当前设备时间来计算挂起时间会更容易。

    希望这会有所帮助。

    【讨论】:

    • 没错,但是如何获取通知时间?
    猜你喜欢
    • 2017-10-22
    • 2012-12-30
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多