Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set expiration date in Android

I have an Android App and I want to give it for testing purpose, after the expiration date the app has to show a dialog and block the commands.

here my code to show dialog and block command

public void expired(){
    bt1.setEnabled(false)
    bt2.setEnabled(false)
    bt3.setEnabled(false)
    bt4.setEnabled(false)
    bt5.setEnabled(false)
Alerts.AppExpiredMessage(Home.this);
}

but How to set expiration date in Android in the form

if(appLicenseExpired){
void expired();
}

verifying that the actual date is antecedent a set expiration date(for example 3rd March 2013)??

like image 324
AndreaF Avatar asked Feb 15 '13 02:02

AndreaF


2 Answers

The following sets isExpired as of 12/31/2014:

GregorianCalendar expDate = new GregorianCalendar( 2013, 11, 31 ); // midnight
GregorianCalendar now = new GregorianCalendar();

boolean isExpired = now.after( expDate );

Note: Months are 0-based. January = 0, December = 11.

like image 80
323go Avatar answered Sep 28 '22 21:09

323go


First of all, there is no method that is 100% guaranteed to prevent hacking because an experienced programmer with a rooted phone can pretty much do anything (including decompiling your app and hack it)

The easiest way is to make the expiration date a fixed date which you can simply hard code it in your app.

If you want to make the app expires after certain period from the installation time (say 30 days), just on the first get the phone identifier (e.g. IMEI) and/or android account (e.g. email) then store it to a server with the installation date. You can store the installation date also on the phone (e.g. SharedPreference) so you can check on every run without going to the server.

Edit

The simplest way to check for the expiry date is to use System.currentTimeMillis() to avoid dealing with TimeZone. You can use online service such as Epoch Time Converter, to know the epoch value for the expiry date and just check it in your code

if(System.currentTimeMillis() >= EXPIRY_EPOCH){

}
like image 44
iTech Avatar answered Sep 28 '22 22:09

iTech