Battery notification in every application that is running - android

Is it possible to have a battery notification in every application that is running?
For example: If I'm going to run an application like Angry Birds, is it possible to have some sort of a notification that will tell me if there is enough time to continue playing it?
This is one of the objectives in our thesis.

If I'm going to run an application like Angry Birds, is it possible to have some sort of a notification that will tell me if there is enough time to continue playing it?
You can play Angry Birds for a second, a minute, an hour, a day, a week, a month, etc. There is no defined "enough time to continue playing it".
Moreover, it is impossible to state definitively how much power a process will run in the future.
Now, you could create some code that attempts to measure historical power consumption of an application (and how the user uses it, which may vary from person to person). You could use that information to make some educated guesses about how long the user could keep using that app. And you could find a way to present that information to the user.
All of that will require, at minimum, custom firmware. It is also very possible that it will require custom hardware that has fine-grained power consumption data collection, such as the Qualcomm MDP.

Related

how to know possibility of waking up in a certain hour using java

I want to make android application to tell me what is the possibility to walk up at fajr time (its prayer time for Muslims), I read about sleep stages and knew that there are 4 sleep stages (Awake, light, deep and rem), each stage takes a duration I want to calculate if this certain time is between the light stage or not, its technically simple but how to do it programmatically.
All these sleep cycles are determined mainly by heart beat per minute, so you can create a android watch app which monitors heart beats or you can see if the users smart watch has any APIs which lets you access these informations for example fitbit API https://dev.fitbit.com/build/reference/web-api/
Depending on this and the users FAJR time you can derive your information.

How do I track app usage time in android?

I have been searched for a long times, but I cannot solve this.
I am developing app usage appplication, and I want to make user can restrict app usage time.
lets say user want to restrict Youtube app usage time for 10 min.
1.
How can I make notification or toaster when Youtube app usage reach 10 min since user click button?(I know event handling)
can I make observer even my app goes backgroud? or even after detroyed?
Base on my search registerAppUsageObserver looks like what I want to, but I cannot use it since its #hide
public void registerAppUsageObserver(int observerId, #NonNull String[] observedEntities,
long timeLimit, #NonNull TimeUnit timeUnit, #NonNull PendingIntent callbackIntent)
I can try to use it by reflection but I think its not recommended.
I got one more good source link but I don't know how to use it.
please help me. thank you.
I've done a fair bit of work in this area. I'd like to direct you to my smartCBT GitHub that reviews in a given period of time what a person has been using their apps for (https://github.com/kris-geyer/smartCBT; in particular, check out https://github.com/kris-geyer/smartCBT/blob/master/app/src/main/java/kg/own/smartcbt/ViewModel/RetrieveUsageRecords.java).
First off, I wouldn't trust the usage stats manager. It's been very unreliable in the past for me. I think what you want to assess usage is usage events (https://developer.android.com/reference/android/app/usage/UsageEvents.Event). These give you a much more fine-grained account of android app usage which seem much more accurate. You will need to get special permission for this. I've actually, empirically tested the accuracy before and it is very high.
For the overall structure of what your app needs I think you want a foreground service that runs in the background routinely logging what the person is using their phone for. This database is only updated when apps are changed, so handling this might be a little tricky but you'll manage.
When the app has identified that the allotted amount of usage time for a particular app is up, then it can direct the user back to your app by launching a new activity from the foreground service. I'm not sure if this is still possible, the android permissions seem to change so quickly. What would be really cool is if you can get the app to play videos of the user telling themselves that they've used their phone too much and be productive.
Best of luck. :)

Android Clock which runs when device off

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

creating method or wait()/notify() in android game

So I will describe what I am trying to doing general.
I have customers(the number of customers available varies at times due to weather, events, or location)
I have a drink stand ( depending on certain factors serving times vary and added time to refill pitcher)
The amount of customers coming to stand vary based on price, events, and popularity.
Customers come to stand and if another customer is still at stand getting served then the others wait in line behind each other. (after so much time in line they complain about wait times)
I want there to be a day timer so even if stand isnt finished serving customers then he loses them because wait time.
So I am not sure if using the Wait()/Notify() way would be best. I was thinking that maybe if I setup Customers as a class and brought it into the activity I am running the sales day in with the Stand info. I would appreciated help with finding a way to do this. I am still going through some other tutorials to see if I can understand a way to do this without screwing up.
Found out that I need to send the customers into a queue when I have them arrive at the stand.
Then also, the day timer will need to be set up to work off a countdown timer.

Time since the app is open in android

Hello
In my android application i would like to get Time since when the app is opened.
Initially what i tried was getting the time when the app is loaded from the server and then taking the difference with the current time from the device.But by doing that if the user changes the time then i willnot be getting the actual time.
Its not posiible to hit the server again for the same.
Is there any way to achieve this in android?
Please share your valuable suggestions.
Thanks in advance:)
Try the "SystemClock" class, "uptimeMillis()" method.
Store the result in a variable when the app starts.
Echoing what I said for your other question, you first need to become familiar with the activity lifecycle and understand the novel meanings (almost meaninglessness) of common words like "open" and "start" in the life of an android app.
There isn't any way you can prevent the user from changing the system time - you just don't have the right to do that to users. Normally this should be a rare event, unless you do something that makes them want to, such as lock them out of a free version of your app after so many minutes. (However if the phone is on a mobile network, presumably the mobile network occasionally adjusts its time to correct for errors in the device's oscillator, or administrative time changes)
What you can do is check the system time on every entry point to your application. If it ever goes backwards, well... something is going on. If the clock has been set back, you could assume no time between the calls with the negative time difference and resume your time meter from there, at least keeping all the previous used time in your record.
It may be that there are cpu cycle counters which you could query and correlate to system time, but this may be highly device specific and may in fact be resettable. And it may get weird if the cpu frequency is demand throttled.
You might be able to set a countdown timer as a bound on the maximum possible time between entry points at which you could meter. I don't know if these work reliably across system time changes or not - ideally they would. Testing or reading the source will reveal.
Use elapsedRealtime in your onCreate() store it. More reliable.

Categories

Resources