I wanted add application signature for some application, which will be valid only for 1 or 2 days. I did enough googling but did not find enough info. So Please let me know how can i make a application get expired in 2 days..
simply add an alarm of calculating time equals to 2 days at the very first start of the app.When the alarm gets expired you will get the callback and set a global flag as false.Code in your app that if that flag is false, display a lock screen
You could save the first start time in SharedPreferences and then on each start compare the current time with the saved one. If the 2 days have passed, you can do what ever action you want.
It will probably not be possible to automatically remove the app from the device though.
If your app sends data to a server, you should store the "first run time" there. Storing it locally on the phone (for example SharedPreferences) is not very safe as it's easily overcome by changing the phone's time settings.
Related
I have an app which is used for collection all day users collecting amount normally offline and then in the evening they uploaded amount online. Sometimes there device date and time is inaccurate so they uploaded wrong data.
At the time of collection my app is getting date and time from the device. Is there any way that app always store accurate date and time without Sim and without the Internet.
You can create a Sqlite Table in application cache when user switch on data,you
can save current server time in that Table and in offline mode you can compare server time with current time. this is the nearest approach to get accurate time
Well, before searching for an app to do this. As a human how can you tell if the date/time is correct without internet?
A possible solution would be a service which counts seconds from the last time the device was connected to the internet (which means it had a correct date/time at that moment) then when you want to add the new amount you can add the seconds to the last time and store this value.
Edit
You will 2 things to achieve this:
BackgroundService
Counter which you can achieve in many ways, I would go the easy way. check this: how-to-measure-elapsed-time
Or you can have an AlarmManager to do this.
One more thing You need to be careful if the device goes off or for some reason, something stopped the service. All of these are user issues and you need to decide how much you want to handle stuff for the user.
You can fix user mistakes by pushing to a SqlLite database every 10~15, but this won't fix if the device went off for hours and then started again at a wrong time - I don't think there is a possible solution for this-.
In my app I want to allow user to be able to use it for 7 days offline usage for free, but want him to connect online once 7 days are done and buy a subscription after that. So basically, I want to lock him out after 7 days from install. The problem is user can very well change system time and trick the app. Also, I cannot use server as the authority as the app is supposed to also work completely offline, except for the time of purchasing subscription.
I can run a background service to keep track of any system time change but I want to avoid doing that.
Is there a straight forward solution which can work even if the device is totally offline for 7 days.
You can save the current time in shared preference and compare it every time you sample it. If you get an older sample the user changed the time backward.
Use remote clock , for even simple read the time of server from mobile in desired time gap and use those number for your app's clock
So this is how I am planning to solve this, though this is not unbreakable but will work for majority of users.
So while signing for trial I get network time and store it as start_time in preferences. Next on each app start and app resume I read the current_time and write to prefs. Once current_time of pref is greater than time of device, we lock the app. Once preferences are not there we ask user to come online as suggested by #Zach
To make preferences editing a little inconvenient to the rooted device guys I am storing data in encrypted form in prefs.
This is still no way unbreakable as one can decompile the apk and read the obfuscated code to guess the algorithm and the key but I guess the value of content in the app is not that high for someone to go through that much pain.
can add syscall and track the time offline, get it from here
I am writing a piece of code in Android that will try to identify when was the last time the Android device was used by the user. By used I mean any operation performed. If the device is not used at all for lets say 1 full day I want to perform some action for it in my service which is running. So basically when the device is not getting used (idle state) that time I want to identify all this.
Is it possible in Android to achieve this? How can I proceed further for this requirement.?
Any pointers will be helpful to identify the device was not used for X days(or hours) and perform some action on it from idle state.
Thanks!
Please follow this tutorial for screen turn On/Off. Hope it will helpful to you.
How to identify when the Android device was used last time?
When first time screen will turn on then you can read system current time and save in shared preferences and from second time (system current time - read last holed value in shared pref) and convert these milliSec to time.
I am creating an application, which will save the current time (with some delay eg. 2 hours) in file, when the user presses a button. Later on, the application will check if the time has passed and do some stuff...
So... I click button in application (time gets saved in file)... I quit application... shut-down phone... I turn it on after 1 hour, get back to application... and I will still have to wait 1 hour until the application will let me do "something"...
QUESTION:
Is there a clock that cannot be changed by the user and keeps running when the device is turned off? I'm currently using SystemClock.elapsedRealtime(), which works fine, because even if users change the time in settings, elapsedRealtime stays the same. The problem is if the device gets turned off, because at every boot elapsedRealtime starts with 0.
I cannot use server time because application will not be connected to Internet.
If there is no such clock, please suggest me another solution.
actualy, you have no chance to get "off" hardware clock data. hardware clocks was just on older phones in the new phones i think nobody need it so they dont build it in hardware. In the old phones there was "hardware" clock but in the new device is nothing like that i think. I did read something about that google want to make some framework or what to implement it. But there is no alarms what are able to start in off mode.
So i am sorry, but i think it is not possible right now..
You could store your time in a database as a DateTime value, indicating Year Day Month Hour Second Millisecond, then you could request for a service to start on boot and read that data creating an alarm that triggers in the remaining time. I would give you a code example, but i'm not really good at java programming so it may be useless, anyway goodluck and try to implement this.
You obviously need to save your data to non-volatile storage. When your app is paused/destroyed by the Android, you should take it as a threat and save your time values to the disks, and then when your app has started again your app should read the data you have written before and keep on running as it would normally.
Well when it comes to question how:
the simplest solution is to use SharedPreferences,
the more complicated and the more flexible one is SQLite Database,
for more data on Android storage I will suggest: Storage Options
I want to know if the user is away for some amount of time. (and then do something according to it.) I cannot depent on screen sleep because user may have disabled it or its value may be greater than timeout of my application.
is there any information like (last user response time ) in android operation system ? and how can i get it?
last user response time = the last interraction time between the user and the phone.
p.s.:i am targetting android 1.6
No, there is no way to tell when was the last time the user interacted with your application in the SDK. You'll have to do something by yourself.
High level explanation of a simple solution:
Assuming you use some base activity inherited by all activities, you can log the current time in your BaseActivity.onPause method. Save it in the app preferences or in a database. When your initial activity starts (onResume) read the same value and compare it the current time.
You can also use Activity.onUserInteraction but saving to preferences/database everytime this is called will considerably slow down your app / feel less responsive!