自首次启动以来的时间 [英] Time since first boot up

查看:121
本文介绍了自首次启动以来的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android应用程序,并遇到了确定系统首次启动时间的问题。我的意思是我需要测量设备首次启动已经花费了时间

I'm developing an android application and hit the problem with determining system first boot up time. I mean i need to measure how much time already passed from device first boot up.

我了解侦听ACTION_BOOT_COMPLETED的解决方案并将任何内容保存在SharedPreferences中,但是我需要另一种解决方案,因为该解决方案在某些情况下不起作用。也许有任何系统属性?

I know about solution with listening for ACTION_BOOT_COMPLETED and save anything in SharedPreferences, but i need another solution, because this one does not work for some cases. Maybe there is any system property?

用例(摘录自讨论


  1. 我收到的每个文件的文件名服务器包含从 System.currentMillis()

  2. 提取的时间戳记
    我比较那些时间戳记以确定哪个文件

  3. 现在,用户可以在几个月前更改系统时间。

  4. 我仍然能够确定用户更改系统时间后下载的最新文件。

  5. 现在,用户将时间更改回原始设置。

  6. 比较时间戳时,在第4步下载的文件始终会获胜。

  1. The filename of each file I receive from server includes a timestamp taken from System.currentMillis()
  2. I compare those timestamps in order to determine, which file the most current one is.
  3. Now, the user changes system time a few months ahead.
  4. I am still able to determine the most current file downloaded after user changed system time.
  5. Now, the user changes time back to original setting.
  6. The file downloaded on step 4 always wins when comparing timestamps.

解决此问题的时间戳是自首次启动(恢复出厂设置后)以来的秒数。就像 SystemClock.elapsedRealtime()一样,但是每次启动后都不会重置。不幸的是,到目前为止的答案告诉我们,这个银弹并不存在。

The silver bullet to solve this problem would be a timestamp that counts seconds since first boot (after factory reset). Just like SystemClock.elapsedRealtime() but without reset after each boot. Unfortunately, the answers so far tell us, that this silver bullet doesn't exist.

但是,许多答案显示了如何解决该问题的多种选择。 OneWorld123对每个答案都进行了评论,这如何满足他的需求。

However, many answers show a great variety of options how to tackle that problem. OneWorld123 commented each answer, how that suited his needs.

推荐答案


也许有任何系统属性?

Maybe there is any system property?

不确定系统属性,但是有 SystemClock 类,该类提供API以使系统正常运行:

Not sure about system property, but there is SystemClock class which provides API's to get system uptime:

SystemClock。 uptimeMillis() 其中


返回自启动以来的毫秒数,不计算花费的时间深度睡眠

您也可以使用 SystemClock.elapsedRealtime() 其中

You may also use SystemClock.elapsedRealtime() which


返回毫秒自启动以来,包括睡眠时间

希望这会有所帮助。

这篇关于自首次启动以来的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆