This can be done by keeping track of two values (stored in sharedPreference
).
Store your first launch date/time
when the app is first launched (i.e. the value doesn't exist).
On every launch also store the current date/time
(which should be called something like last launch date
in your settings).
When starting, first check if the current date of the device
is less than the stored last launch date
- if it is then the user has changed the date/time - or procured a time travel device :) In this case you can display a warning message telling the user to behave, or just fail silently and prevent the user from accessing the feature(s).
If the date is okay, go ahead and update the value to the new current date
(for future launches) and then check if the period has expired or not and make the feature available as needed.
This should work offline, except for users that have rooted their devices and can modify values in sharedPreference
- but they should be a minority. To prevent root users, you will need to employ an online service.
Also just a warning that this can cause false positives when users travel (crossing time zones). But you should be able to handle that as a special case by also checking time zones (if needed).