问题
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:
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.
来源:https://stackoverflow.com/questions/21081017/total-uptime-on-android-and-iphone