警报管理器setRepeat中的问题

时间:2019-05-14 10:22:33

标签: android

我需要每分钟重复我的警报管理器。所以我写了这样的代码

  val calendar = Calendar.getInstance()
    calendar.timeInMillis = System.currentTimeMillis()
    calendar.add(Calendar.MINUTE, 0)
    calendar.set(Calendar.SECOND, 0)

    val triggerAt = System.currentTimeMillis()
    val oneMinute = (60 * 1000).toLong()

    val alarmMgr = getSystemService(Context.ALARM_SERVICE) as AlarmManager
    val intent = Intent(this, BootCompleteReceiver::class.java)
    val alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0)
    alarmMgr.cancel(alarmIntent)


    alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME,
            SystemClock.elapsedRealtime() + 1000 * 60,
            1000 * 60, alarmIntent)

但有时会在一分钟内重复一次。

请帮助我!

0 个答案:

没有答案