AlarmManager not working as expected in sleep mode on S5 Neo

让人想犯罪 __ 提交于 2019-11-30 13:44:06
Neige

You should probably use

AlarmManager#setExact(int type, long triggerAtMillis, PendingIntent operation)

instead of

AlarmManager#set(int type, long triggerAtMillis, PendingIntent operation))

Take a look

From google :

AlarmManager#set(int type, long triggerAtMillis, PendingIntent operation))

Note: Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later. The OS will use this policy in order to "batch" alarms together across the entire system, minimizing the number of times the device needs to "wake up" and minimizing battery use. In general, alarms scheduled in the near future will not be deferred as long as alarms scheduled far in the future.

Edit :

What i am using for an alarm application :

Manifest :

<uses-permission android:name="android.permission.WAKE_LOCK"/>

Java Code :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo(nextAlarm.getTimeInMillis(), pendingIntent);
  alarmManager.setAlarmClock(alarmClockInfo, pendingIntent);
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  alarmManager.setExact(android.app.AlarmManager.RTC_WAKEUP, nextAlarm.getTimeInMillis(), pendingIntent);
}else {
  alarmManager.set(android.app.AlarmManager.RTC_WAKEUP, nextAlarm.getTimeInMillis(), pendingIntent);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!