In My app I'll use an Alarm to notify user for event, the problem is
on Android version 6.x-
The alarm is delivered after same minutes of the exact times.
This is only when the device enter on sleeping mode.
I tried to wakelock the device before the alarm, but to no avail.
Can anyone help me? this is my code
Set the alarms
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), pendingIntent);
if (minutesBefore > 0) {
beforeCalendar.add(Calendar.MINUTE, -minutesBefore);
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, beforeCalendar.getTimeInMillis(), beforePendingIntent);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), pendingIntent);
if (minutesBefore > 0) {
beforeCalendar.add(Calendar.MINUTE, -minutesBefore);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, beforeCalendar.getTimeInMillis(), beforePendingIntent);
}
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, alarmCalendar.getTimeInMillis(), pendingIntent);
if (minutesBefore > 0) {
beforeCalendar.add(Calendar.MINUTE, -minutesBefore);
alarmManager.set(AlarmManager.RTC_WAKEUP, beforeCalendar.getTimeInMillis(), beforePendingIntent);
}
}
Weaklock
when i receive the alarm by broadcastreceiver im try to wake up device from doze mode by this code
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//Object flags;
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Alarm_WakeLock");
wl.acquire();
But the alarm still delivered after same minutes!!