Can a HTML5 app in a browser keep an Android device awake? - android

I want to create a small HTML5 app that runs in a browser window. Its purpose is to track my geolocation and the heart rate with Javascript while cycling or running. The screen does not need to stay on (as I don't even want to show a map), the phone just needs to continue collecting location data and not stop the bluetooth connection to the heart rate sensor.
Is this possible with vanilla HTML5? Or do I need something native wrapped around the app? So basically I just want to press a button when I start my tour, and then hit the stop button when I come back. A simple data collector, no fancy GUI neccessary.
I don't have problems with the app itself (using the Generic Sensor and Geolocation API), just with the interruption issues when the phone goes to sleep.

Related

How to detect user interaction with phone in flutter?

Is there any way to detect user interaction/activity with the phone in flutter?
I want to know which app the user is using or if the user is using his phone or not. I just want to know if the user's phone is in active state or not.
Yes, I know I can use motion sensors like Gyroscope and all but is there any other way to detect phone activity in flutter?
The idea is my app will be running in the background and it will track user interaction with the phone.
If the user is using his phone like playing game, watching video or any other activity then it will show me that phone/user is active.
All I found on the internet is to track activity like walking, running motion activity.
Is there any other way to track phone activeness?

MobileFirst app running while device is locked?

On the initial load of our application, we make hundreds of worklight invokeProcedure calls, that take up to 20 minutes to an hour to fully complete. (Each one takes less than 10 seconds, so works fine.) However if the device lock screen comes up it pauses the application and if I don't respond quickly enough to the device lock screen, the worklight invokeProcedure gets interrupted and stops our initial load process.
Is there a way to configure the application on Windows, iOS, and Android to continue when the lock screen is showing?
You may want to look at a combination of preventing the screen lock from occurring and the background handling Idan Adar suggests, to provide a more graceful and controllable UX.
For iOS, setting the idelTimerDisabled property at the right places in your processing could prevent the screen lock, and then if other external device operations occur, you could gracefully complete and save process state of the rest of your procedure calls, resuming them when the app becomes active again.
[UIApplication sharedApplication].idleTimerDisabled = YES;
A similar approach should be supported in other platforms.
This is not a built-in functionality AFAIK.
For iOS, you need to enable "background fetch" mode:
https://www.ibm.com/developerworks/community/blogs/worklight/entry/ios_background_fetch?lang=en
For Android you may need to do this with a Cordova plug-in: IBM Worklight - How to use Worklight in a background process
As for Windows... no idea...

Does disconnecting Android Phone Display Hardware Stop Apps

I am running an accelerometer based android app that will run for a few months while phone is on and does nothing else. Some phone allow display not to go to sleep at all which allows my app run fine infinitely. The screen also has only a black display and nothing else apart from background accelerometer listener and occasional http posts. My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
My question is if I remove the display screen while the app is running, would that stop the operating system and/or my app?
In short, it depends on your app architecture (otherwise i.e. music players would require to keep screen on to work). Depending on task you are really doing you may use Alarm Manager to periodically fire your code, or use Service.

Check volume button usage when screen is off

For this question I'm going to quote another user who got no response to their question:
I've written an Andoid app that uses the hardware Volume buttons for another purpose.
It works fine if the app is running and visible, but when I turn the
screen off or let it time out, the button clicks don't get into my
handlers.
Does anyone know if there is a way to detect these button clicks when
the screen is off?
Source: AV695's question
I'm working on an app myself that makes use of the volume buttons, but as this user also noted, the normal behavior of checking buttons with onKeyPress stops working once the screen is off. This is because the Activity gets paused on screen off.
Is there a way to keep the activity running while the screen is off, or check for the usage of the volume buttons when the screen is off? I tried using a Service for this before but it's impossible to check for the volume keys like that as noted by Commonsware.
I doubt that this is supported (without resorting to a battery-draining wakelock) at either the platform, kernel, or underlying radio firmware levels without modifications to the last to bring volume presses during sleep to the attention of the kernel.
Within the realm of reasonable system-ROM modifications, a more reasonable one might be to modify an existing open source ROM for the device to insert some custom platform level code into the handling of the power button usually used to wake up the device preparatory to unlocking it - that at least we know does get the attention of the kernel. That code could then inform the user by sound or vibration if there are unacknowledged notifications.
You could optionally wait briefly, check device orientation, or look for another key press to avoid doing this in an annoying way when the user is holding the device outside their pocket and trying to unlock it.
Or you could not use the volume key and just set a timer to wake up every 15 minutes and vibrate if there are unacknowledged notifications, avoiding the need to fumble in ones pockets.
You mention it's a custom request: if implies it's one off or low-volume, another option to consider would be that a few vendors have "bluetooth watches" out with an SDK that lets you push notifications from an android device.
If you can capture the notification when it's generated, you could push it to the user's wrist, and then let the phone go back to sleep.
You cannot intercept the key while your application is in background, but instead of listening to the KeyPress itself. You can register a ContentObserver, as described in this question.
As Chris Stratton mentioned, the only way to keep your App alive is by using battery-draining wake locks.
However, since I found myself in the same situation, I came up with another solution. Unfortunately, you'll need a rooted device as well as the Xposed framework.
With Xposed, which replaces the zygot process so you can hook yourself into any constructor and method of the system, you will be able to catch the raw KeyEvents before the system handles them.
This is done in PhoneWindowManager.interceptKeyBeforeQueueing(). By using a XC_MethodHook, you can use beforeHookedMethod() on the afore mentioned method to catch every hardware button event, even if the device is in deep sleep.
After catching events you are interested in, you can create a temporary wake lock to do your things but don't forget to release the wake lock after you finished your work.
A good example of how to accomplish this is the Xposed Torch Module.
If you, however, rely on a non rooted system, the bad news is that it's simply not possible without draining the battery...
I was also trying to implement volume button press detection in my app and I left that part to be developed later once the core part is done. I was able to detect volume key press while screen is on even when phone is locked, from a background service.
Background Video Recorder 2 (BVR2) (and possible BVR1 also, I did not try) is one of the apps that can detect volume key press even when screen is off. While trying to implement volume key detection while screen is off in my app, I installed BVR2, hoping to find how it works. To my surprise it gave my app the ablity to detect volume keys even when screen is off. My app had a ContentObserver to monitor volume changes, but was not working when screen is off. When BVR2 is active my app also could detect volume key press when screen is off. Still digging.
But BVR2 has its own trigger action, that is to record video, an action you may not want to occur just for the sake of you application detecting volume key presses.
Another app is QuickClick. This app can give your app what it lacks, the power to detect volume key presses even when screen is off, without extra unwanted actions. Just install QuickClick and do not configure any action. Create a ContentObserver to monitor for stream volume changes and you are ready. You app will now be able to detect volume key presses even when screen is off.
Please note that my app runs as a background service.
Both of the apps mentioned above are meant for other uses, but uses volume key detection to perform action. I am in no way connected to any of the apps mentioned.
If these apps, and possibly dozens others, can detect volume key press, it can be done. I request experts to find out how to do it, so that we can implement in our app without relying on another app.
If you find this answer useful, please up-vote.
I am not sure if it is as simple as this but check this android blog:
Allowing applications to play nice(r) with each other: Handling remote control buttons
It explains the usage of a broadcast receiver that receives the up/down volume controls and other music controls.
In summary you should use registerMediaButtonEventReceiver

How to properly kill an Android activity, that isn't a background process

There seems to be a lot of controversy about how to stop applications in Android, so I'll explain what I'm trying to do and why in hopes that I can receive some guidance on how to properly implement the functionality I'm looking for.
I got tired of plugging my phone into power when I get into the car, connecting the headphones, turning BT on, turning WiFi off, and then launching "Car Home" because my dock doesn't do so automatically - it's just a piece of plastic mounted to the dash.
So my application automatically does these things when I connect power - and when I disconnect power, it turns BT off and WiFi back on, but unfortunately, Car Home is still running.
I want to automate the entire process, so I never have to launch (or shut down) Car Home, and make getting in and out of the car a little less frustrating.
I know Froyo introduces ActivityManager's killBackgroundProcesses method, but this doesn't seem to work for me. It does seem to be focused around background processes, but what I've read online seems people want to use it to stop foreground applications.
I've also tried restartPackage from Eclair unsuccessfully, so I'm looking for advice.
What is the best way for me to tell the "Car Home" application to stop specifically because power is disconnected and I'm getting out of the car, without me having to navigate to it's home page and click "Exit"?
Have you seen UiModeManager?
This class provides access to the system uimode services. These services allow applications to control UI modes of the device. It provides functionality to disable the car mode and it gives access to the night mode settings.

Categories

Resources