Josh Beckwith Josh Beckwith - 1 year ago 66
Android Question

Android: calculating time away from app

In my app, I'd like to keep track of time away from the app, so that if the user is away for say, 2 hours, and come back, they receive 1 in game currency.

In practice I could easily do this by using a date object to get the current time in onStop, saving that date object, and comparing it to a new date object when they return.

However, I have a feeling this can easily be spoofed by change the internal date settings.

Is there a more secure way? Should I just put a cap on how many hours away you can bank up? I'd love some insight. Thanks as always.

Answer Source

you can try to make more secure code in the app, but the safest way is to request something from a server

if you are app is already using internet permissions consider making an HTTP request to get time.

look at this site for example

if you have backend to support your app that would be extra better

if you are not using internet permissions it might not be worth it to add it just for this, you might consider a different "offline" solution

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download