我正在尝试获取Android应用的原子时间。我使用http://hi-android.info/src/android/net/SntpClient.java.html作为NTP客户端和以下代码来实现NTP(=来自SntpClient.java的示例代码):
SntpClient client = new SntpClient();
if (client.requestTime("time.foo.com")) {
long now = client.getNtpTime() + SystemClock.elapsedRealtime() - client.getNtpTimeReference();
}
我在此列表中尝试了不同的服务器:http://mindprod.com/jgloss/timesources.html,但“client.requestTime(”SERVER“)”始终为“false”......
我的代码:
SntpClient client = new SntpClient();
if (client.requestTime("hera.limescope.net", 10000)) {
long now = client.getNtpTime() + SystemClock.elapsedRealtime() - client.getNtpTimeReference();
textAtomicClock.setText(String.valueOf(now));
}
我做错了什么?
FREDDI
答案 0 :(得分:0)
发现我的错误!我不知道我必须在后台处理ntp任务......我用Androids AsyncTask函数解决了这个问题。感谢所有帮助过我的人!