Android:Intent.ACTION_TIME_CHANGED 有任何其他信息吗?
Intent.ACTION_TIME_CHANGED 是否有任何其他信息? getData() 或 getExtras() 中没有任何内容。
我想知道:
手机在设置新时间之前的时间;
谁更改了时间:用户(手动)还是电话运营商?
欢迎通过任何其他方式获取这些信息!
Is there any additional information available from Intent.ACTION_TIME_CHANGED? There's nothing in getData() or getExtras().
I would like to know:
The time phone had before setting new time;
Who has changed the time: the user (manually) or the phone carrier?
Any other way to get those informations are welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我查看了 Android 的源代码,这个广播没有任何额外内容。因此,没有办法了解这些信息。
I looked into source code of Android and this broadcast doesn't have any extras. So, there is no way to learn this info.
如果先前时间的准确性不那么重要,您可以做一件事。您可以通过以下方式获得前一个时间,精确度为 +/- 1 分钟。
注册广播操作 ACTION_TIME_TICK (这将每分钟广播一次)。
当时间滴答作响时,如果当前时间与上次滴答时间相差超过 1 分钟,则可以推断发生了时间变化。之后,您只需将新时间更新为共享首选项即可。就这样。
2.1 如果是第一次广播,请在共享首选项中输入当前系统时间。
2.2 否则将当前时间与之前输入的时间进行比较,如果出现超过1分钟的差异,则表示时间时间发生了变化。然后将新的系统时间更新为SP。
快乐编码。
You can do one thing if the accuracy of previous time is not that important. You can get the previous time with +/- 1 minute accurate by following way..
Register for broadcast action ACTION_TIME_TICK (This will be broadcasted every minute).
When ever the time ticks, if there is a difference of more than 1 minute between your current time and last tick time, you can infer that there occured a time change. After that you just update the new time to shared preference. Thats all.
2.1 If first time broadcast, Enter the current system time to Shared Preference.
2.2 else compare the current time with previously entered time and if occurs a difference of more than 1 minute, means the time time has changed. Then update the new system time to SP.
Happy coding.
我认为不可能了解时间更改的原因,尽管通过将 System.currentTimeMillis() 与 SystemClock.elapsedRealtime() 进行比较来找出时间更改的量应该是可能的,因为 SystemClock.elapsedRealtime() 不会得到在这种情况下进行了调整。
一个例子是这样的:
I don't think getting the why the time changed is possible, though finding out the amount the time was changed should be possible by comparing System.currentTimeMillis() to the SystemClock.elapsedRealtime(), since SystemClock.elapsedRealtime() does not get adjusted in this case.
An example would be something like: