Get actual device offline time

I am developing an Android application. I need to solve the following problem in my application:

1) The application can work both online and offline. The application has the ability to create and save NOTES inside the application. Also, when the application gets an Internet connection, I need to send NOTES to the backend server. I have a field called "DATECREATED" in each NOTE (date-time when the actual NOTE was created)

QUESTION: If the user incorrectly set the DateTime on the device, my application sends the wrong DATETIME to the server. I am wondering how can I solve the problem? Any ideas would be noticeable.

+5
source share
2 answers

When you end up sending a message to your server, just add that specific time. new Date().getTime() will provide you with a value that you can use to compare with the datetime of your server. If this is, for example, after 2 hours, then just set the time for sending the message after 2 hours.

So, send the time when the message was sent by the user, and the time when it was sent.

+3
source

You can get the current date and time using network time.

 LocationManager locManager = (LocationManager) mContext .getSystemService(mContext.LOCATION_SERVICE); long lastSyncTime = locManager.getLastKnownLocation( LocationManager.NETWORK_PROVIDER).getTime(); 

I used it to get location based time in my application. I think it will work both online and offline.

0
source

All Articles