我怎样才能获得"联播网中;时间(从"自动"设置称为QUOT;使用网络提供的值"),没有时间在手机上?
我想在我的应用程序,以找到一种方法来同步的日期和时间的东西由外部源给出。
I would like in my application to find a way to synch the date and time with something given by an external source.
我不希望使用手机的时间,因为我可能会得到各地真实的时间也许5分钟的差别。 5分钟额外的或更少= 10分钟!
I don't want to use the phone time because I might get a difference of maybe 5 minutes around real time. and 5 minutes extra or less = 10 minutes!
我已经听说了GPS卫星或网络天线时间信息。
I have heard about time information in the GPS satellites or in Network antennas.
我曾尝试与System.getCurrentTime,但我得到的器件的电流,所以,如果我的设备设置提前5分钟,就显示错误的时间。
I have tried with System.getCurrentTime but i get the current the of the device, so, if my device is set up 5 minutes earlier, it display the wrong time.
修改
要作一个简短的问题:我怎么能得到这个时间
To make a short question: how can I get this time?
我不知道,但发现这个问题有意思。所以,我挖在Android code ...感谢开源:)
I didn't know, but found the question interesting. So I dug in the android code... Thanks open-source :)
您显示屏幕为 DateTimeSettings
。勾选使用网络提供的值相关联的共享preference 字符串KEY_AUTO_TIME =auto_time;
,也为 Settings.System .AUTO_TIME
The screen you show is DateTimeSettings
. The checkbox "Use network-provided values" is associated to the shared preference String KEY_AUTO_TIME = "auto_time";
and also to Settings.System.AUTO_TIME
这是设置观察观察到的名为 mAutoTimeObserver
在2个网络 ServiceStateTracker
S:
GsmServiceStateTracker
和 CdmaServiceStateTracker
。
This settings is observed by an observed called mAutoTimeObserver
in the 2 network ServiceStateTracker
s:
GsmServiceStateTracker
and CdmaServiceStateTracker
.
两种实现调用一个方法称为 revertToNitz()
当设置为真。
显然 NITZ 是NTP在载体世界等效
Both implementations call a method called revertToNitz()
when the settings becomes true.
Apparently NITZ is the equivalent of NTP in the carrier world.
底线:您可以将时间设定为revertToNitz为提供的载体感谢值()
。
不幸的是,我还没有找到一种机制来获取网络时间。
如果你真的需要做到这一点,我很害怕,你必须复制这些 ServiceStateTracker
取值实现,搭上由框架(我想)提出的意图,并添加getter到 mSavedTime
。
Bottom line: You can set the time to the value provided by the carrier thanks to revertToNitz()
.
Unfortunately, I haven't found a mechanism to get the network time.
If you really need to do this, I'm afraid, you'll have to copy these ServiceStateTracker
s implementations, catch the intent raised by the framework (I suppose), and add a getter to mSavedTime
.