How does my app tell if the current date is the real current date?
My goal is to create a version of the app that will expire after a certain date has passed. I want the time to expire at an absolute date, not a relative date,
Hence my app uses uses this code to check the current time:
Calendar nowCalendar = Calendar.getInstance();
However, the user can manipulate this by changing their Date & Time settings.
Question: How doe开发者_StackOverflows my app tell if the user has manipulated their Date Time? or How do I tell if the user has set the "automatic" Date Time setting?
Can you suggest the simplest way to check the internet for the current time?
Each time your app is starts or exits save the current datetime. If next time the system date is an earlier value then you know the time has been tampered with.
You can't have a perfect solution, only if you have internet access. If you do, then there are a million ways you can ckeck for the time, or even call back to your server to check whether the trial license is still valid.
One way to check for internet time is making a simple request to an HTTP server. For example to google (you should use your own server for this).
Request:
HEAD / HTTP/1.1
Host: google.com
Response:
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Wed, 09 Mar 2011 16:04:48 GMT
Expires: Fri, 08 Apr 2011 16:04:48 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
As you can see all HTTP servers report back teir current system date in the Date
header.
But then again, this does not matter at all. If Internet connection is essential for your software to work you can use online license check on your own server. If not, then users can turn their connection off with the push of a button while using it.
You can access to the real time throw Network Time Protocol. You can see the definition in Wikipedia
精彩评论