I already have a service that sends how much time by minutes a user was online or offline every 15 mins and only after the state has changed from the previous one (online to offline or vice versa). So, basically, I can see the minutes count as a value when selecting a parameter, for example, ONLINE_TIME (in screenshot called TIME), and see events in the last 30 mins with values of how much time the user was online by minutes.
My main goal is to see in Firebase, how much percent time of the day users was online and offline. Any ideas on how could I achieve this? Thanks.
Related
I have an app where user can scan details from his device and send details via https to my backend service so I can evaluate his data and send other data back to his mobile device.
Now I need to implement background task which would do previously mentioned scan once in a week, let's say on friday even when the application is not running. I don't want to send back to device any data if scan is run in background task not from user directly. I just need to send data from device to service.
I would like to choose the best solution which seems like WorkManager with periodic work request (https://developer.android.com/reference/androidx/work/PeriodicWorkRequest). However I have few questions.
Let's say I would like to make a scan every friday. Only constraint is that user has to be connected to the internet. If user install my application and execute it on monday I would set the repeat interval for 5 days and flex interval for 1 day. So background work should be executed last day which is friday. But after this background scan, period should change from 5 days to 7 days, so it can execute every next friday. How can I make this change? Should I run OneTime background work which run scan after 5 days and create repeated background task with 7 days period?
If user is not connected to internet all friday, is it gonna take another period (7 days in this case) since next execute or will it execute on saturday? If not on saturday, what should I do to run it on saturday?
If user is not connected to internet for half of friday, it is going to execute my background work on friday afternoon with 7 days interval and 1 flex day interval. However since the user wasn't connected for half day, next background work will be execute from friday afternoon to saturday midday? Or will it execute only in friday just like previous work? If not how can I prevent this behaviour?
If Work Manager can't ensure, that background task will be executed on friday, what should I use than. I think that one day is a quite huge interval and it shouldn't be such problem, right?
I am grateful for every opinion and advice.
Since that time I put here the question I have gained some experience so I am going to type some advice for users with same questions.
If you want to proceed background task once per several days, I recommend you to set period interval for one day and check if last time that background work was processed was already your expected period. For example if you want period once per week, set the period for one day. In every day background work check if last work was before 7 days. With this condition if background is not processed after 7 days, it will be started after 8 days or 9 days but not after 14 days as it would be if period was set on 7 days.
I also recommend you to check battery in your mobile settings, find your application and make sure, that your application will no be forced stop due to battery optimalization. Because force stop will also kill your background work.
I want to get the total usage time of an app in the specified time interval and how many times the user had opened that app in that time interval for all apps?
I already fetched the last time used of apps.
Please need help
For those who are saying it is not possible here is a screenshot of an app available on store showing usage count
First time asking a question. I appreciate any thoughts/feedback you may have.
Part of the functionality of an app I am working on requires that an internal counter in the app be in perfect sync with a counter on a remote server.
More specifically, there are 86,400 seconds in a day. Assume on a server I start a counter that ticks from 1 to 86,400 progressing at one tick a second. When it gets to 86,400 it starts over at 1. This then repeats indefinitely.
Part of the functionality of the app is the first time it is launched by the user it will connect to the server and sync a similar running counter within the app to perfectly match the counter on the server. (e.g. at the exact same time that the server counter ticks to perhaps 10,215.....so should the app counter be ticking to 10,215.)
Assume perhaps thousands of users have the app. I need it so that the thousands of individual app users now have 1 - 86,400 counters all running exactly in sync with each other. With the idea that a user only has to have their app perform this server sync a single time. After it's synced, the counters within the apps would then run in unison in perpetuity.
Questions:
1) Is this feasible to do? For the reasons I need this to occur, it literally cannot be off by even a second or two. They all have to match perfectly.
2) Would varying internet and/or phone speed by user be a problem (during the sync process)? Again, it is a one time sync. It does not have to sync on a continuous, real-time basis. Nonetheless, the first sync does have to be perfect.
3) If the answer to the above is that it is doable.....getting greedy here, can I sync it at even faster speeds? Instead of the counter just counting up one tick per second (i.e. 86,400 ticks per day), can the counter tick at perhaps a rate of 1/10 of a second (864,000 ticks per day). At that super fast tick speed, could the perfect sync still be accomplished?
While not the exact reason for needing the above, to give perspective.....imagine I had 100 people sitting in a room download the app. They then open the app which then all perfectly sync to the server so that they are all now running their individual counters in perfect unison. At that point, they lose internet connectivity (yet, the counter continues to run within the app in their phone.) If the app was programmed to start playing a particular song when the internal app counter reached tick X, all 100 phones would start playing the song at the exact same time (when their counters in unison reached tick X).
Sorry for the long question, but wanted to lay out my issue. Thanks everyone!
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-.
I'm developing an android game that has points. There are some ways to get points and the one of them is to open the game every day. I thought of two ways to implement this but the both have security problems.
The first way: system date
The app's service gets current system date and checks if bonus was awarded for this date; if it wasn't then award and write this date to the database (suppose this database is encrypted and there is no way to change the data inside it).
The problem: cheater can change system date and get points again and again.
Possible ways of protection:
Fix installation date. If current system date is less that installation date it's a cheater, don't award points. Weakness: cheater can change date to the future not to the past.
The same as first but additionally we can check that installation date is greater that app release date (hardcoded, yes). Weakness: first not but growing every day.
Check date using the internet. If current system date is less or greater than internet date by more than 24 hours it's a cheater, don't award points. Weakness: cheater can disable the internet.
The second way: timer
Suppose that we want to make bonus every day at 00:00. When user starts the game first time (suppose at 20:00) calculate how many time left before the bonus time (4 hours). Set timer for this time (4 hours). When the timer goes off award points and start the new one for 24 hours and then similarly.
The problem: device can be rebooted and the timer will be destroyed. So after reboot we need to repeat algorithm as the first time: calculate how many time left before the bonus time and start the timer. Cheater can change time to 23:55 and reboot the device and get points; and than do it again and again.
The third way: timer and database
The same as the second way but additionally timer writes time left to database every minute (for example) and after reboot restore this value.
The problem: I see no weakness but it awards points every 24 hours but not every day.
That's all...
By the way: I've tested the first way of cheating with some games and it works. But some others are protected from this.
I would be happy to hear any ideas or advice. And thanks for your time.