同步时间的记录数据上的多个Android设备 [英] Sync Time for Recording Data on Multiple Android Devices

查看:180
本文介绍了同步时间的记录数据上的多个Android设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题可能会稍微啰嗦,但是开了很多建议。

This question may be slightly long-winded, but is open for many suggestions.

问题描述:
我们有几个API级别8(Android 2.2的),我们将使用记录加速度数据在游乐园,即坐在过山车上的myTouch设备。我们也有一个可视化功能,可以让我们绘制并查看加速度计分,作为他们被记录时间的函数。这里我们有一个两难!在Android设备上的系统时间都不尽相同,也不能设置为同一时间以毫秒precision(含分钟precision,这是可怕的只有手动)。

Problem Statement:
We have several API level 8 (Android 2.2) MyTouch devices that we will be using for recording acceleration data at an amusement park, namely on a roller coaster. We also have a visualization feature that allows us to plot and view the accelerometer points as a function of time that they were recorded at. Here is where we have a dilemma! The system times on the Android devices aren't all the same, nor can they be set to the same time with millisecond precision (only manually with minute precision, which is awful).

解决方案尝试:
所以,我首先根据在应用程序的启动中找到一个GPS时间使出记录数据。漫长的过程很短:得到GPS的时间,让系统时间,得到的差异,并在记录一个数据点,再次获得系统时间,并添加不同的返回到的时候,标签,作为开始记录时间,并增加200毫秒为每个从那里记录的数据点。但是,也有2个问题(用于获取GPS时间):

Solution Attempts:
So, I first resorted to recording data according to a GPS time found at the start of the app. Long process short: get GPS time, get System time, get difference, and upon recording a data point, get system time again and add the difference back onto the time, label that as starting time of recording, and increment by 200 milliseconds for each recorded data point from there. However, there are 2 problems (for getting GPS time):

  • 使用 getLastKnownLocation()不是太准确。事实上,它似乎非常不准确。它给我倍,9分钟关当前GMT / UTC时间。巧合的是,然而,系统时间也是近9分钟关在Android设备上...... GPS时间和系统时间之间的差别通常是1000和5000毫秒(1〜5秒)之间。我想有机会的话我的code是错误的。我贴在下面给你看。

  • Using getLastKnownLocation() isn't too accurate. Actually, it seems very inaccurate. It is giving me times that are 9 minutes off the current GMT/UTC time. Coincidentally, however, system time is also nearly 9 minutes off on the Android device... the difference between GPS time and System time is usually between 1000 and 5000 milliseconds (1 to 5 seconds). I suppose there is a chance my code is wrong. I pasted it below for you to see.

requestSingleUpdate()将是巨大的使用,因为它会得到一个更近的位置,也许是一个非常准确的时间。问题?需要API级别9 ......我们没有设备。

requestSingleUpdate() would be great to use, as it would get a more recent location and perhaps a very accurate time. Problem? Requires API level 9... devices we don't have.

思路:
这里有一个想法,我虽然 - 如果我莫名其妙地拉着一个全球性的时间从一个网站,并使用从那里拉的记录时间的时间?问题就在这里 - 我不知道该怎么做,它只是一厢情愿的我的想法......

Ideas:
Here's an idea I had though - what if I somehow pulled a global time from a website and used the time pulled from there as the time of recording? Problem here - I have no idea how to do that, it is just wishful thinking of mine...

另一个想法 - 是否有某种全球性的getTime()型的功能,我根本不知道

Another idea - is there some sort of global getTime()-type of function that I simply don't know about?

推理为什么我要Android的从一个类似时钟拉时间:
想象一下,两个人坐在了过山车 - 一个在前座,一个在后面。当记录数据时,前面的人显然会在人的意志(我们希望看到这对我们的可视化图表)背面稍前体验加速度。这就是为什么它是至关重要的,以毫秒precision,这些点是根据一个单一的,全球性的时间记录下来。

Reasoning why I want Android's to pull time from a similar clock:
Imagine two people sitting on a roller coaster - one in the front seat, one on the back. When recording data, the person in front will obviously experience accelerations slightly before the person in the back will (and we want to see this on our visualization graph). That is why is it crucial, to millisecond precision, that these points are recorded according to a single, global time.

code:

Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);

if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
    mLocationManager.requestLocationUpdates(mLocationManager.getBestProvider(c, true), 0, 0, AmusementPark.this);
    Criteria criteria = new Criteria();
    String bestProvider = mLocationManager.getBestProvider(criteria, false);
    Location location = mLocationManager.getLastKnownLocation(bestProvider);

    try {

        gpsTime = location.getTime();
        systemTime = System.currentTimeMillis();
        timeDif = gpsTime - systemTime;
        Log.e("timedif", "GPS: " + gpsTime + ", System: " + systemTime +", Dif: " + timeDif);

    } catch (NullPointerException e){

    }

}


更新:
这里,有人提出一种服务器的的getTime()。我真的很喜欢他的code /答案,但是这是什么服务器和/或我如何设置一个,如果这是最好的解决办法?


Update:
Here, someone suggests a sort of "server" getTime(). I really like his code/answer, but what is this "server" and/or how do I set one up, if this is the best solution?

推荐答案

我觉得服务器响应是指在该职位是设立一个专门的时间服务器。基本上,你会设置一些硬件都全部使用你的应用程序的人将连接,以获得所需的时间。这可能是更多的努力比你愿意把

I think the "server" the responder is referring to in that post is to set up a dedicated time server. Basically you'd be setting up some hardware that all of the people using your app would connect to in order to get the time. It may be more effort than you are willing to put in.

您会需要以下,

  1. 一些备用的硬件(可能是取决于你有多少人认为将使用您的应用程序简单,只要一台电脑运行Tomcat的,复杂的如专用服务器机架上。)或订阅域服务器/虚拟主机。

  1. Some spare hardware (could be as simple as a computer running tomcat, or as complex as a dedicated server rack depending on how many people you think will be using your app.) or a subscription to a domain server/web host.

有的只是返回每当应用程序请求它的时间Web服务。

Some web service that just returns the time whenever an app requests it.

你需要让你的服务器/ web服务大众,这是完全是另外一个头疼的问题。

You'd need to make your server/webservice public, which is a whole other headache.

我不知道这将是你最好的解决方案,无论是因为它会依赖网络连接到达专用服务器。有一对夫妇的替代解决方案,你可以试试:

I'm not sure that would be your best solution either as it would depend on network connectivity to reach your dedicated server. There are a couple of alternate solutions you can try:

我不知道,如果你的应用程序将是公共或专门用于研究使用。如果是后者,这将是与一群你认识的人,可以与协调,其实我建议你刚才下载时钟同步,同步你的手机在同一时间服务器,然后执行你的应用程序。

I don't know if your app is going to be public or used specifically for research. If it is the latter and it will be with a group of people you know and can coordinate with, I actually recommend that you just download ClockSync, sync up your phones to the same time server, and then execute your app.

如果您的应用程序将被分发到人,你不会有接触,那么也许你最好的选择是让你的应用程序做一个NTP服务器的连接,并抢在时间的方式。这里有公共NTP服务器,你可以用一个列表: http://www.pool.ntp.org/ EN /

If your app is going to be distributed to people you won't have contact with, then perhaps your best bet is to get your app to do a connection to one ntp server and grab the time that way. Here are a list of public ntp servers you can use: http://www.pool.ntp.org/en/

下面是一些更多的信息:

Here's some more information:

时钟同步

样品code 用于制造SNTP连接

Sample code for making an SNTP connection

我希望这些信息可以利用你在做决定。

I hope that information can be of use to you in making a decision.

这篇关于同步时间的记录数据上的多个Android设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆