0

This is my first time to ask here on Stackoverflow and I am apparently having a hard time on this one. How could I identify if the user changed the device's date in order to activate a date-based code actions?

I really need to compare the actual date and device date without internet connection.

For example: When I click this button, it would only open in August 29. Changing the date would allow me to access the function of the button.

2 Answers2

1

You can use a Network Time Protocol. Which provides the network time and date so it can't be tricked by the user changing the phone date.

Google has one open source at: This link


EDIT

Which provides this code as sample:

SntpClient client = new SntpClient();
if (client.requestTime("time.foo.com")) {
   long now = client.getNtpTime() + SystemClock.elapsedRealtime() - client.getNtpTimeReference();
}

where it puts time.foo.com you should put time.google.com. You might need a timeout in milliseconds to add to the requestTime(host,timeout_millis) method.


And for NTP server you can use

time.google.com

Provided Here

Ivan
  • 782
  • 11
  • 23
0

If you can make sure that when your app is installed it has correct time then, you may implement a listener to know manual clock change and then do what you want to do. Reference: Is there a way to detect when the user has changed the clock time on their device?.

There are 2 more options, one to get time using GPS and other is to get time from Network. Not too sure about the network, it is something NTP related stuff will explore when I get a chance. Let me know about your implementation.

Calvin
  • 617
  • 1
  • 12
  • 34