Android:Intent.ACTION_TIME_CHANGED 有任何其他信息吗?

发布于 2024-12-10 07:34:18 字数 208 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

轻拂→两袖风尘 2024-12-17 07:34:18

我查看了 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.

淡淡绿茶香 2024-12-17 07:34:18

如果先前时间的准确性不那么重要,您可以做一件事。您可以通过以下方式获得前一个时间,精确度为 +/- 1 分钟。

注册广播操作 ACTION_TIME_TICK (这将每分钟广播一次)。

当时间滴答作响时,如果当前时间与上次滴答时间相差超过 1 分钟,则可以推断发生了时间变化。之后,您只需将新时间更新为共享首选项即可。就这样。

  1. 注册 ACTION_TIME_TICK 广播。
  2. 收到广播时:
    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.

  1. Register for ACTION_TIME_TICK broadcast.
  2. When broadcast received :
    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.

勿忘初心 2024-12-17 07:34:18

我认为不可能了解时间更改的原因,尽管通过将 System.currentTimeMillis() 与 SystemClock.elapsedRealtime() 进行比较来找出时间更改的量应该是可能的,因为 SystemClock.elapsedRealtime() 不会得到在这种情况下进行了调整。

一个例子是这样的:

private long realtimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime();
private void onReceive(Context context, Intent intent) {
    if(Intent.ACTION_TIME_CHANGED.equals(intent.getAction()) {
        long prevRealtimeOffset = realtimeOffset;
        realtimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        Log.i(TAG, "Clock was adjusted by: " + (realtimeOffset - prevRealtimeOffset) + " ms");
    }
}

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:

private long realtimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime();
private void onReceive(Context context, Intent intent) {
    if(Intent.ACTION_TIME_CHANGED.equals(intent.getAction()) {
        long prevRealtimeOffset = realtimeOffset;
        realtimeOffset = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        Log.i(TAG, "Clock was adjusted by: " + (realtimeOffset - prevRealtimeOffset) + " ms");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文