How to time-bomb an Android application?
Asked Answered
P

2

10

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 the application is officially in beta.

Proportional answered 3/8, 2009 at 17:27 Comment(1)
I think this is already answered here : https://mcmap.net/q/195323/-creating-an-android-trial-application-that-expires-after-a-fixed-time-period Well, not with any code examplesBallance
B
16

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();
    }
Brickle answered 4/8, 2009 at 0:53 Comment(6)
The Java Calendar class month numbering start at 0, not 1.Brickle
So, 15th September would be: (2009, 8 , 15) Think thats correct.Proportional
What if the user changes the date to the past ?Minion
@GuidoGarcía See the 3rd technique in this answer. https://mcmap.net/q/195323/-creating-an-android-trial-application-that-expires-after-a-fixed-time-periodReportage
Why did you use onResume() ?Saurian
If my memory serves, there is a certain order that procedures are called. In theory, an Android app could never be closed, so OnStart() would be a bad place to check for expiration. OnResume() happens whenever you switch to an app, so I'm confident it will be called. I haven't touched Android programming in about a decade, so things might have changed..Brickle
P
4

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.

Polydactyl answered 4/8, 2009 at 2:0 Comment(6)
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.Proportional
@Proportional that's because it's a pain in the ass. Look up AsyncTask.Grapnel
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(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.Polydactyl
@Polydactyl That will be amazing. I was thinking wouldn't it be cool to power such a system with the AppEngine.Proportional
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. broschb.blogspot.com/2009/08/…Polydactyl
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 broschb.blogspot.com/2009/08/android-and-google-app-engine.htmlPolydactyl

© 2022 - 2024 — McMap. All rights reserved.