我需要每分钟重复我的警报管理器。所以我写了这样的代码
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)
但有时会在一分钟内重复一次。
请帮助我!