Reputation: 23
Does anyone know of a way to get the time the device has been in sleep? I am trying to get Awake Time for the device battery and I can get the total time since boot using SystemClock, but they do not have a method for sleepTime. If I could get sleep time, I could do totalTime - sleepTime and get the awakeTime, but not sure on how to get sleep time.
Any suggestions?
Thanks
Upvotes: 2
Views: 1028
Reputation: 1006859
SystemClock.elapsedRealtime()
is "the time since the system was booted, and include deep sleep".
SystemClock.uptimeMillis()
is "counted in milliseconds since the system was booted. This clock stops when the system enters deep sleep (CPU off, display dark, device waiting for external input), but is not affected by clock scaling, idle, or other power saving mechanisms."
Hence, SystemClock.elapsedRealtime()-SystemClock.uptimeMillis()
should be the amount of time in "deep sleep".
Upvotes: 7