Dear android developers,
I'm trying to implement the sntpclient class in my application but it didn't work.
in my code I have the following lines:
public void onClickBtn(View v)
{
SntpClient client = new SntpClient();
if (client.requestTime("pool.ntp.org", 10)) {
long now = client.getNtpTime() + SystemClock.elapsedRealtime() - client.getNtpTimeReference();
Toast.makeText(this, "Offset: " + now, Toast.LENGTH_LONG).show();
}
}
I really don't know what the meaning of network timeout is in this case.
It would be great, when someone has any idea or tip for me.
Thanks in advance!
You should put it in AsyncTask like this :
class GetNTPAsynctask extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... params) {
private SntpClient sntpClient = new SntpClient();
return sntpClient.requestTime("pool.ntp.org", 30000);
}
}
Timeout: network timeout in milliseconds. So i use 30000 mean 30 seconds.