android检测用户修改设备时钟时间
我的应用程序需要正确的时间(不能依赖设备时间,因为用户可以更改它+运营商可能不可用或不支持 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在任何平台上都不要依赖客户端来获取准确的时间。
那么根据定义,你就无法获得准确的时间。
您可以创建自己的固件来阻止用户设置时间。
不,因为发送广播的可能原因有多种。
我可以告诉你,我在 Android 源代码中看到的 ACTION_TIME_CHANGED 的唯一接收者是通过
registerReceiver()
注册的接收者,而不是清单。不过,此广播不符合需要registerReceiver()
的通常模式。您尝试一下可能会更简单。Never rely on the client for accurate time, on any platform.
Then you cannot have accurate time, by definition.
You can create your own firmware that prevents the user from setting the time.
No, insofar as there are several possible reasons why that broadcast will be sent.
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 whereregisterReceiver()
is required, though. It is probably simpler for you to just try it.