How to sync times of two devices with Android NTP?

Viewed 2771

We have 2 android devices running same application that users see their GUI. Time synchronization is curicial for us. To make them have same time we have the settings as below.

Use these commands in boot and after every 5 minutes but it seems after 8 9 hours of uptime two android devices have different times with respect to their seconds. ex:

busybox watch -n 1 date

DEVICE 1: (Android 6 Marshmallow) 2020-03-10 09:16:33

DEVICE 2: (Android 6 Marshmallow) 2020-03-10 09:16:38

settings put global ntp_server pool.ntp.org
settings put global auto_time 0
settings put global auto_time 1

After that we also tried below commands but not worked

settings put global ntp_polling_interval 10
settings put global ntp_pollinginterval 10
settings put global ntppollinginterval 10

Any suggestions?

1 Answers

Android 6.0 has a well known time issue, differences of several minutes per day were reported.

This has been fixed with 6.0.1, if you can update your devices that would circumvent the issue.

As for NTP, you can set the server, and auto_time to 1 but it will refresh only every 24*60*60*1000ms (one usual day).

If rooted you could just install a ntp-app to do that in shorter timeframes or add a cronjob. Or restart the phone all the time.

From a coding perspective, you could change your app to not use the system-time but poll the NTP-Server yourself every now and then, and use the system time only to decide when it's time to do so.

Related