Permalink
Browse files

[Mobile] Updated NotifyTimesReceiver to use appropriate AlarmManager.…

…set() method when Doze is applicable.
  • Loading branch information...
thecosmicfrog committed Jun 19, 2018
1 parent 2e98d33 commit 97612436dd0c4afed34815cd0f6004bc24b50937
@@ -232,9 +232,29 @@ public void onReceive(Context context, Intent intent) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(
Context.ALARM_SERVICE
);
alarmManager.set(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + notifyDelayMillis, pendingIntent
);
/*
* Due to the restrictions enforced by Doze, we need to ensure our notification will fire.
* Check to see which API the device is using, and trigger the appropriate set() method.
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
/* Wake up the devices in Doze mode. */
alarmManager.setExactAndAllowWhileIdle(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + notifyDelayMillis, pendingIntent
);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
/* Wake up the device in Idle mode. */
alarmManager.setExact(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + notifyDelayMillis, pendingIntent
);
} else {
/* Wake up the device. */
alarmManager.set(
AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + notifyDelayMillis, pendingIntent
);
}
}
}

0 comments on commit 9761243

Please sign in to comment.