How can I get the “network” time, (from the “Automatic” setting called “Use network-provided values”), NOT the time on the phone?

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 ServiceStateTrackers:
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 ServiceStateTrackers implementations, catch the intent raised by the framework (I suppose), and add a getter to mSavedTime.

Leave a Comment