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?
Asked
Active
Viewed 2,242 times
1 Answers
0
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.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
I forgot to mention I am looking for a value which cannot be directly modified by the end user. Otherwise, simply getting the current epoch time would've been sufficient for my problem. I am looking for a timer which persists across boots and keeps running while my app is not being started. – Tri-Edge AI Jan 12 '14 at 22:43
-
@Tri-EdgeAI: "I forgot to mention I am looking for a value which cannot be directly modified by the end user" -- the user cannot modify the installation time of a package, other than by uninstalling it – CommonsWare Jan 12 '14 at 23:04
-
The user can modify the current time on his device, which means I cannot really tell how much time has passed since the installation of the package. Please read more carefully. – Tri-Edge AI Jan 12 '14 at 23:22
-