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?
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.
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.
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.
Related
I need a way to be able to tell if a user has uninstalled and reinstalled the android application. I use shared preferences for when the user CLOSES the app, however, I need to save out a variable that will let me know if the user has ever opened the app on this device in the past.
(Basically the user is awarded items in the game when first starting the game, after they are used the player could essentially just uninstall and reinstall and use the items again) I need a variable that gets saved in the android registry that will tell me if the player has ever opened the app before (even if they have previously uninstalled).
Is this possible?
I am a beginner in Android development. I want to build a service that once started, must keep running.
Step 1.) Once user will install the app give some input, service will start. (i'll use IntentService)
Step 2.) Now user moves to other app/close my app. I want to make sure Service should keep running and processing/saving info with current timestamps.
Questions:
1.) How I make sure that the service keeps running/saving data even if user returns after say, 1 month on my app.
2.) I read that every app is a new user and separate VM is provided by the Android, question is when an app is considered to be closed?
3.) If my app closes, related services will also close then?
1.) How I make sure that the service keeps running/saving data even if user returns after say, 1 month on my app.
Once user installs app, you can start STICKY service but make sure you inform the user as well as Android OS by making it run on foreground with on going notification. it will help your service to run for long time without being killed by Android OS.
1 month is long period, user may reboot the cell in between. and you will need to restart your service. so you should register for reboot complete event .
2.) I read that every app is a new user and separate VM is provided by the Android, question is when an app is considered to be closed?
There is no condition like considered to be closed.Actually, when user installs app, it is by default in stopped mode, it gets activated when user opens your app for first time. and application can go back to stopped mode again whenever user force stop your app.
3.) If my app closes, related services will also close then?
If you are considering that app is considered as closed when user don't use the app,your service won't close unless Android OS kills it in low memory situation.you may make it foreground as suggested earlier to convey Android OS that you are doing important things,nothing is wrong,so kill me only at last when you don't have any other options left
I have created an android app using phonegap. I want to run the app to limit its usage to only 5 times means user can open this app only for 5 times after that user will not be able to open it instead it will show a message.
How can i do this ?
Depending on your requirements you could probably have a setting that you increment and save every time the app is opened, then when you see the app is over it's open limit you'd block access.
With this method clearing the data on the phone would reset the value. For this to be very reliable you'd have to have some sort of device ID that gets sent to a server that would determine if the app has been opened before and how many times.
Is there anyway to know that when an application is launched for the firsttime? I dont want to use sharedpref because when the user cleardata manually it clears all the data.
That is the point of clearing data, the user may want to tell your app to consider itself freshly installed without having to necessarily uninstall the app. You should not be trying to break that expectation. That said.....
You could create a file on the SD card and check for the existence of that file to determine if your app is being run for the first time.
Do not use the normal openFileOutput() calls in android as that will be cleared when the user clears data as well.
Unless the user wipes all files on the SD card, the file should remain in existence. Also, you can do both, a shared preference and the file and then check for one or the other, just in case.
Use your own server. Just store the unique android id on your server in the first time user launches your application. But you need internet for this.
I want to restrict my app's launch based on the number
of times the user has accessed my app in between a particular
time interval. So I thought that if I know my app's previous
launch, I could achieve it. If there is something else possible ,
plz someone out there help me..
On your app launch, increment and store a variable in Shared Preferences. Check this at each start.