0

How can I get correct day from Android device. Now I have a problem to get the correct day if user is offline. If the user has no internet connection and the user has changed his date in device. How can I get the correct date like whatsapp?

Some ideas? I have already tested get date from location.

update I want to get correct date regardless of user has changed his date on device and the device is offline.

  • Could you be more specific about what is incorrect? You should also provide some code. My suggestion is to try [multiple options](https://stackoverflow.com/questions/5369682/get-current-time-and-date-on-android). – mrek May 11 '18 at 15:28
  • Not sure if this helps, but [you can detect the user date change](https://stackoverflow.com/a/17175444/3894977). – mrek May 11 '18 at 15:31

1 Answers1

2

I assume your goal is to prevent a user from bluffing their date backwards. Thus extending an otherwise free period of usage?

If so, the answer is simple. Add a sharedpreference that stores the active date whenever the app starts up if the device has internet.

If the device does not have internet, then check your last known sharedpreference usage date and see if the device date is before that. This will at least let you know that they rolled back. Its not perfect, because if they decided not to use your app for a month, then rolled it back before opening, it could still give false positives of looking like they are ok to use it. However, it is very unlikely situation.

The most likely situation is they will open the app, get a warning that their date exceeded usage, and then they will try to cheat by going offline and changing the clock, at this point you already set a flag that they expired, or you know the last usage date. Either way you have the information to prevent usage.

You could also just require internet access for the app to be used, that's what I typically do to avoid being cheated on trials.

If that is not your goal, please elaborate more so we can help you with a better solution for your situation.

Sam
  • 5,342
  • 1
  • 23
  • 39
  • Thanks for the help. I have a app there user can send message to another user. I want to get the correct date when message is sent if user is offline and has changed his date. Can I get date from TimeZone from api 19? – BenjiProgramming May 11 '18 at 16:49
  • oh got it, well the timestamp should be indicative of the received phone received time on the received app. and indicative of the sent phone sent time on the sent app. If they changed their timezone and it skews your timestamp, there isn't a lot you can do about that, not sure I would do anything about it. It may be overkill handling a very niche unlikely scenario. – Sam May 11 '18 at 18:25
  • okey thanks for the help. I hope the users not change date;) – BenjiProgramming May 11 '18 at 18:52