I didn't know, but found the question interesting. So I dug in the android code... Thanks open-source :)
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
This settings is observed by an observed called mAutoTimeObserver
in the 2 network ServiceStateTracker
s:
GsmServiceStateTracker
and CdmaServiceStateTracker
.
Both implementations call a method called revertToNitz()
when the settings becomes true.
Apparently NITZ is the equivalent of NTP in the carrier world.
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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…