Android的同步通过GPS时间的设备?时间、设备、Android、GPS

2023-09-04 03:37:57 作者:气势比天高

短版:

问题:我需要一些Android设备做一些事情在完全相同的时间(在CA 100毫秒)。例如,我希望所有设备及时发挥了一定的声音previously确定的点。

问:我可以用GPS时间,以确保设备的时钟的同步是

更长的版本:

有Android设备有几个人在同一户外地点(为某些特定体育赛事)。所有设备信号完全相同的时间特定的事件。 (什么时候将前手被确定,这是不重要的,它们做在完全相同那个时候,只要他们这样做在同一时间)。 FWIW:这些活动将有助于人们开始在同一时间的体育活动

下面是假设,我可以做:

可能存在或可能不小区覆盖。 (这是在室外,可能是远城区) 该设备可以或可以不被连接到互联网。 (有些人可能没有一个数据计划) 设备可以互相交谈。如果设备未连接到互联网,它们将通过无线连接(虽然无线可以不具有互联网网关)。 的设备外(而不是在建筑物内)。 (这是很好的,这意味着所有设备均可获得GPS定位) 的装置在物理上彼此接近(即,在300平方米)。 (不知道这很重要)

我不能使用内部时钟知道什么时候打事件:用户可以手动更改时间,即使设备设置为从一个蜂窝网络时,该网络可能无法提供明确的时间。两个设备可能被记入不同的网络,因此他们的时间可能不会同步非常好。

目前应用程序启动时,每个设备可以要求一个GPS定位并保存GPS时间和它的内部时钟之间的差异。现在主可以(通过使用它的内部时钟,并减去偏移它以前保存)宣布,在此基础上的GPS时间的事件。

这会不会是precise足够的,可靠的?

许多在此先感谢, 安德烈亚斯·莱特纳

解决方案   

我可以利用GPS时间,以确保设备的时钟的是同步?

是啊,为什么不,GPS时间是超precise。但是,除非你是一个系统的apk,则不能更改系统时间。

时间同步显示屏,NTP网络授时仪

您可以从毫秒的时间差currentTimeMillis()和 Location.getTime() onLocationChanged()回调。使用requestSingleUpdate()

我只想补充一点,如果用户有一个数据连接,他们可以使用NTP时间,这更加准确,因为GPS的内部时钟可能漂移和纠正还需要一段时间。

Short version:

Problem: I need several Android devices to do something at the exact same time (within ca 100 milliseconds). For example, I want all devices to play a certain sound at previously determined point in time.

Question: Could I use GPS time to make sure the devices clock's are synced?

Longer version:

Several people having Android devices are in the same outdoor location (for some specific sports event). All devices should signal certain events at the exact same time. (What time will be determined before hand and it is not important that they do it at exactly that time, as long as they do it at the same time). FWIW: those events will help the people to start their sporting activity at the same time.

Here are assumptions I can make:

There may or may not be cell coverage. (It is outdoors and may be far of urban areas) The devices may or may not be connected to the internet. (Some people might not have a data plan) Devices can talk to each other. If the devices are not connected to the internet they will be connected via wifi (though the wifi may not have an internet gateway). The devices are outside (and not inside buildings). (That's good, it means all devices can get a GPS fix) The devices are physically close to each other (i.e., within 300 m2). (Not sure if that's important)

I cannot use the internal clock to know when to play events: users can manually change the time and even if a device is set to get the time from a cellular network, that network might not provide the exact right time. Two devices might be booked into different networks and hence their time might not be synced very well.

At app startup, each device could ask for a GPS fix and save the difference between the GPS time and its internal clock. Now the master could announce events based on this GPS time (by using it's internal clock and substracting the offset it saved earlier).

Will this be precise enough and reliable?

Many thanks in advance, Andreas Leitner

解决方案

Could I use GPS time to make sure the devices clock's are synced?

Yeah why not, GPS time is super precise. However unless yours is a system apk, you can't change the System time.

You can get the time difference in milliseconds from currentTimeMillis() and Location.getTime() in the onLocationChanged() callback. Use requestSingleUpdate()

I just want to add that, if the user has a data connection they can use NTP time, which is even more accurate, as the GPS internal clock might drift and correcting it takes a while.