android检测用户修改设备时钟时间

发布于 2024-12-12 04:36:28 字数 213 浏览 0 评论 0原文

我的应用程序需要正确的时间(不能依赖设备时间,因为用户可以更改它+运营商可能不可用或不支持 NITZ)。最初我使用 http 调用到受信任的服务器,但是有时会出现网络不可用的情况。

我还可以使用其他选项吗?

我可以依靠广播 ACTION_TIME_CHANGED 来检测用户修改了设备时钟吗?我的应用程序是否始终需要运行才能收到此通知(我想避免这种情况)?

谢谢!

My App requires correct time (can not rely on device time since the user can change it + carrier might be not available or doesnt support NITZ). Initially I use http calls to a trusted server, however there are situations when network is not available.

Is there any other option I can use?

Can I rely on broadcast ACTION_TIME_CHANGED to detect that the user modofied the device clock? Does my app always need to be running in order to get this notification (this I would like to avoid)?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

天赋异禀 2024-12-19 04:36:28

我的应用程序需要正确的时间

在任何平台上都不要依赖客户端来获取准确的时间。

最初我使用 http 调用到受信任的服务器,但是有时会出现网络不可用的情况。

那么根据定义,你就无法获得准确的时间。

还有其他我可以使用的选项吗?

您可以创建自己的固件来阻止用户设置时间。

我可以依靠广播 ACTION_TIME_CHANGED 来检测用户修改了设备时钟吗?

不,因为发送广播的可能原因有多种。

我的应用程序是否始终需要运行才能收到此通知(我想避免这种情况)?

我可以告诉你,我在 Android 源代码中看到的 ACTION_TIME_CHANGED 的唯一接收者是通过 registerReceiver() 注册的接收者,而不是清单。不过,此广播不符合需要 registerReceiver() 的通常模式。您尝试一下可能会更简单。

My App requires correct time

Never rely on the client for accurate time, on any platform.

Initially I use http calls to a trusted server, however there are situations when network is not available.

Then you cannot have accurate time, by definition.

Is there any other option I can use?

You can create your own firmware that prevents the user from setting the time.

Can I rely on broadcast ACTION_TIME_CHANGED to detect that the user modofied the device clock?

No, insofar as there are several possible reasons why that broadcast will be sent.

Does my app always need to be running in order to get this notification (this I would like to avoid)?

I can tell you that the only receivers of ACTION_TIME_CHANGED that I see in the Android source code are ones that register for it via registerReceiver(), not the manifest. This broadcast does not fit the usual pattern where registerReceiver() is required, though. It is probably simpler for you to just try it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文