Is Android using NTP to sync time?

后端 未结 4 821
野性不改
野性不改 2020-12-04 11:31

Do Android Devices use the network time protocol (NTP) to synchronize the time?

In my Device-Settings I see a checkbox with the following text \"synchronize with net

4条回答
  •  悲哀的现实
    2020-12-04 11:58

    I know about Android ICS that it uses a custom service called: NetworkTimeUpdateService. This service also implements a NTP time synchronization via the NtpTrustedTime singleton.

    In NtpTrustedTime the default NTP server is requested from the Android system string source:

    final Resources res = context.getResources();
    
    final String defaultServer = res.getString(
                                    com.android.internal.R.string.config_ntpServer);
    

    If the automatic time sync option in the system settings is checked and no NITZ time service is available then the time will be synchronized with the NTP server from com.android.internal.R.string.config_ntpServer.

    To get the value of com.android.internal.R.string.config_ntpServer you can use the following method:

        final Resources res = this.getResources();
        final int id = Resources.getSystem().getIdentifier(
                           "config_ntpServer", "string","android");
        final String defaultServer = res.getString(id);
    

提交回复
热议问题