views:

852

answers:

3

Hello does anyone have a code example of how I can time bomb an Android application so It will not work after a given date?

I would like to release a "beta" application for testing but would like to make sure it will only work while I have the application officially in beta.

Thanks.

+4  A: 

I think this is already answered here : http://stackoverflow.com/questions/995719/android-trial-applications

Well, not with any code examples

Tommy
+3  A: 

I would suggest using the Calendar class and having your application checking the current date against your expiration date in your OnResume(s).

The code would look something like this:

    protected void onResume()
    {   
        super.onResume();

        Calendar expirationDate = Calendar.getInstance();
        expirationDate.set(2009, 7, 3);  //hardcoded expiration date
        Calendar t = Calendar.getInstance();  //Calendar with current time/date
        if (t.compareTo(expirationDate) == 1)
           finish();
    }
Will
For some reason this isn't working for me. The "now" time is always wrong... like, 1 month ago wrong.
fiXedd
The Java Calendar class month numbering start at 0, not 1.
Will
So, 15th September would be:(2009, 8 , 15)Think thats correct.
Tom
I believe that should be correct.
Will
What if the user changes the date to the past ?
Guido
+1  A: 

Also depending on your application, you may want to have the expiration call make a call to a webserver, that way if you wanted to extend or change the date, it would be dynamic and would not cause the applications to expire prematurely. Just my 2 cents.

broschb
This would be a great solution. I would love to do this but I am unsure on how to best program using web servers and android.
Tom
@Tom that's because it's a pain in the ass. Look up AsyncTask.
fiXedd
It's actually fairly simple and straight forward. I have been playing around with this, and am going to write a blog(broschb.blogspot.com) post on this, and will update this once I have. But I used GoogleAppEngine and Restlet(http://www.restlet.org/). Restlet has libraries for GAE, and Android. With this it is pretty simple to get something simple set up. I'll try and write something up in the next few days and post back.
broschb
@broschb That will be amazing. I was thinking wouldn't it be cool to power such a system with the AppEngine.
Tom
I wrote an article on setting up the first part of this, with a small example for getting the app engine setup. I'll try to get the second part of the post done with the android integration this weekend, in the meantime you can see how simple it is to get GAE going. The post is here. http://broschb.blogspot.com/2009/08/restful-service-on-google-app-engine.html
broschb
@broschb Thanks! I am reading it now!
Tom
I have installed ver 2.0 of resetlet and I have alot of JARs except " org.restlet.gae.jar " ideas? If you could, email me at [email protected]
Tom
Tom, I sent you an email, and also updated the post to specify which version is needed.
broschb
I created another followup tutorial, that shows how to tie all of this together by calling an application in GAE, and retrieve and expire date from Android. You can see it here http://broschb.blogspot.com/2009/08/android-and-google-app-engine.html
broschb