How to set expiration date in Android

AndreaF picture AndreaF · Feb 15, 2013 · Viewed 7.2k times · Source

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)??

Answer

323go picture 323go · Feb 15, 2013

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.