Total uptime on Android and iPhone

China☆狼群 提交于 2019-12-25 02:55:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!