0

I created an application for pharma.

Now I want to stop that application after launching 10 times, and also even user can not launch an app after uninstall and reinstall the app.

How could I do that?

Does anyone have an idea?

RivieraKid
  • 5,923
  • 4
  • 38
  • 47
naleshmadur
  • 95
  • 1
  • 10

3 Answers3

3

Now i want to stop that application after launching 10 times

You are welcome to maintain some sort of counter and disable your launch activity when it should no longer be used, via PackageManager and setComponentEnabledSetting().

and also even user can not launch an app after uninstall and reinstall the app

This is not possible. You can store your counter on external storage, some place that will be retained even after an uninstall. However, the user can get rid of your counter file whenever the user wants.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
3

If your application uses net connection you can send a parameter to your service with unique device id. In your service you get the device id and compare with your database. If device id is not in the database (first open of app) create a row with device id and the time stamp. Everytime the user opens the app control the timestamp with today. If it is more than 10 days you can lock the app.

Murat Nafiz
  • 1,438
  • 17
  • 28
  • 1
    Here's a good post on "best practices" if you decide to use "device id": http://stackoverflow.com/a/2853253/1337412 – theelfismike May 05 '12 at 15:52
  • but when user uninstall the app and again reinstall it will open. how to prevent that? – naleshmadur May 06 '12 at 07:16
  • no it will not open. Cause device id is an unique id for every phone. and if the user uninstall the app and reinstall it, the device id parameter will be still same. Therefore you can check timestamp (which is more than 10 days) and close the app again – Murat Nafiz May 06 '12 at 12:43
0

You can use SharedPreferences.

  • Create an int variable = 0 and store it to SharedPreferences
  • In onCreate method, increment this variable
  • Check (In onCreate method), if this variable > 10 - call finish()

Thats all. Hope this help.

Rubycon
  • 18,156
  • 10
  • 49
  • 70