calculate app uptime - android

Viewed 1017

I am trying to get the power consumption details made by each installed app in a list. But since I do not have root access, I know I won't be able to use adb shell commands to get battery usage info for all processes.

What I think I can do is get the uptime for each installed app, get the total time my battery has been disconnected (by saving timestamp when ACTION_POWER_DISCONNECTED happens), and calculating -

( app_runtime * 100 ) / total_time_battery_disconnected

However, I am unable to obtain the most basic info about an app -> how long it has been running ? I can use activeSince on RunningServices, but that is not the solution here.

The class ApplicationInfo does not provide any such methods either.

Is there any way to get this detail ? I see so many bloatware apps showing my the total consumption made by every app I have installed with the running since time also shown, so I know it is possible. But how ?

I looked into this article on Android Battery Life. But this is limited to Android internals.

Even tried UsageStats, but its not working, returning Zero when querying usage stats list.

1 Answers
Related