user2275236
user2275236

Reputation: 23

android - how can I get time in sleep

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

Answers (1)

CommonsWare
CommonsWare

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

Related Questions