Total uptime on Android and iPhone

2.2k views Asked by At

As far as I know both OSes allow me to obtain the current uptime since the last boot, but is there a way to obtain the total uptime since the OS was first started, or since my application was installed or something like that? I was thinking of running a background service on boot to accumulate that for me, but turns out I can't really do that on iOS or something. Any ideas how this can be achieved?

1

There are 1 answers

4
CommonsWare On

Speaking for Android:

is there a way to obtain the total uptime since the OS was first started

Not directly, but see below for a quasi-workaround.

or since my application was installed

PackageManager and getPackageInfo() can return you a PackageInfo object for some package, such as your own package name. That has a long firstInstallTime that will indicate when the package was installed.

Since you can get PackageInfo objects for any package, you're welcome to cook up some algorithm to try to approximate the time the device was first used, by finding the time of the oldest app install. However, you'd have to filter out pre-installed apps, and that will get tricky. I certainly would not want to rely upon this.