Jaiprakash Soni
Jaiprakash Soni

Reputation: 4112

One month restiction for application free use

Requirement:
In my application I want to allow user to free use all features for one month from the day of application's first run. For this I have store first run date in application database and compare first run date with current date every time when application launch.

Implementation:
For getting current date we have several function like Calendar.getInstance(); Date date=new Date(); these function will return the date\datetime of the standard "wall" clock (time and date). According to document Which can be set by the user or the phone network.

The Problem:
Every thing seems to be work fine but what if user change date from Setting and set it to past date. For example user have first run application on 7 June 2013 so after 6 July 2013 application must show that he have to purchase subscription, but if user change date of device back to 30 June etc. then the restriction will not work.
So is there any why to implement it correctly?
Is there any why to get actual time of device that is not be editable by user?
Edit:
Application can work offline, so user can turn off internet connectivity.

Upvotes: 2

Views: 157

Answers (4)

Vinay W
Vinay W

Reputation: 10190

Event(APP_INSTALL) -> storeOnServer(INSTALL_TIME_KEY,getTimeFromServer());

Event(APP_LAUNCH) -> IF(getTimeFromServer -getStoredTime(INSTALL_TIME_KEY) >30)
  -> showTrialPeriodEndedAlert()
  -> quitApp();

Upvotes: 0

frenziedherring
frenziedherring

Reputation: 2265

If it's a possibility, you could use a one-shot GPS request to get a time value. The user can't change the GPS time that it receives. Adding the permission is a pain if you don't need it, but this would prevent bad behavior caused by the user mucking with the date/time.

Upvotes: 1

Bex
Bex

Reputation: 2925

Store the first day it was used and the last day it was used, and listen to the ACTION_TIME_CHANGED intent. Also, try using an AlarmManager.

Or if you have network, store it in a database off the phone.

But you probably need to ask yourself if someone really would change the date of their phone just to use your app. It would seriously mess up a lot of things for them: alarms, calenders, syncing to other services and so on. I don't think it is a problem in reality.

Upvotes: 1

ElPedro
ElPedro

Reputation: 586

How about storing two dates - the date the app was first used and the date it was last used. 30 minus the difference between the two dates will give you the number of days remaining and if the current date is earlier than the last used date you know that they have changed the date back.

Just an idea - not tried it but in theory it should work.

Upvotes: 1

Related Questions