Android的 - 网络日期/时间日期、时间、网络、Android

2023-09-06 13:16:12 作者:你敢天荒,我就敢地老

我在写为Android的应用程序的过程。我需要让我的用户捕捉到它们的当前位置和放大器;登录日期/时间,这种事情发生了。美中不足的是,该日期/时间不能是东西,用户可以通过调整日期/时间他们的设备上发生变化。

I'm in the process of writing an app for Android. I need to allow my users to capture their current location & log the date/time that this happened. The catch is that the date/time cannot be something that the user can change by adjusting the date/time on their device.

您可以点我在正确的方向为塔使用定位服务时获得蜂窝网络的日期/时间,以及如何获取GPS日期/时间。

Can you point me in the right direction for obtaining the Cellular Network date/time when using location services for towers, and also how to obtain the GPS date/time.

任何帮助是AP preciated,谢谢!

Any help is appreciated, thank you!

推荐答案

GPS或网络时间戳可以使用的 LocationListener的 Android的位置的API中。

GPS or Network timestamp can be retrieved by using the LocationListener in the Android Location API.

请参阅开源GPSTest项目完全工作的例子: https://github.com/barbeau/gpstest

See the open-source GPSTest project for a fully working example: https://github.com/barbeau/gpstest

您可以要求听任何网络位置更新:

You can request to listen to either Network location updates:

lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,这一点);

或GPS位置更新:

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,这一点);

然后,当一个位置被传递到LocationListener.onLocationChanged方法,可以从该位置读取时间戳:

Then, when a location is passed into the LocationListener.onLocationChanged method, you can read the timestamp from that location:

@Override
public void onLocationChanged(Location location) {
    Log.i("Timestamp", "New timestamp: " + location.getTime());
}

另一种选择是使一个请求到网络时间协议(NTP)服务器,这是完全独立的装置和电池网络。

Another option is to make a request to a Network Time Protocol (NTP) server, which is completely independent of the device and cell network.

有关实施NTP客户端的详细信息,请参阅这篇文章:

See this post for details on implementing an NTP client:

使用NTP服务

 
精彩推荐
图片推荐