Android browser Javascript events when minimised - android

I'm building a webapp for Android smartphones that runs with the OS internet browser. the main interface is to input data. the data is added to a queue (android 1.5: gears, android 2.x: html5). Each 5 minutes (using setTimeout), the script looks if an internet connection is active, and if so, sends all the queue to the server.
If the phone is plugged on the wall and the webpage is ontop, the timeout works. if the browser is minimized or another application runs on top of it, the timeout doesn't work. if the phone is in sleep mode it doesn't work either.
Can only native apps runs in background?

can only native apps runs in
background?
Certainly, I would not expect the browser to be waking up the device, for your sleep mode scenario. Apparently, based on your symptoms, they pause all Javascript threads when the browser itself is paused. That is not terribly shocking, given the battery problems that leaving those scripts running might cause.

You could also base it on system time, rather than just setTimeout. That way it would at least run when they returned focus to the browser.

Related

Can not send request when screen is locked

My React Native (Android) application sends requests to the server when some events are triggered. But when I lock phone screen and in a few minutes event is triggered, app try to send request, but it fails. I tried fetch (error Network request failed) and XMLHttpRequest.
On some devices it works fine and I can't understand it depends on Android version or on device model.
Why does it happen and why on some (not all) devices? How can I fix it? Thanks!
Hello issue not because of react-native development but as per android guideline,
Whenever device in Doze mode you can not access network or network resource directly for that you need to start some foreground service in your application or we can say foreground service, Actually, I don't know much about how to create and start foreground service in react-native, But maybe this word help you, Here also official document regarding doze mode
https://developer.android.com/training/monitoring-device-state/doze-standby

Android webRTC call in a Foreground Service

I am creating an Android app (Java code) that has an audio call feature.
I managed to make it work using the webRTC framework.
I wanted to make my audio call behave like WhatsApp and Messenger, where those apps keep the audio call running even if the user stops the app from apps history, or starts using another app.
So, I decided to migrate the webRTC code from an Activity to a Foreground Service.
My Audio Call Activity handles the UI, displaying friend photo, name, call timer ...
So I had to make communication between my Activity and my Foreground Service through binding and sending android.os.Message object.
Everything works fine when using SAMSUNG devices, if I kill the app, I could return to the Call activity by clicking the foreground service's notification, and the audio call keeps working until I hang up.
My problem appeared when i used a Xiaomi device (redmi note7), if i kill the app, the audio call stops, cause my Foreground Service is restarted.
Even after enabling "Autostart" from settings.
I searched in here for a solution but all the answers i found didn't satisfy my need, cause i can't just accept my Service being restarted.
If i want to resume the audio call, i have to re-call the friend again !
So, the question is :
How to prevent Xiaomi, Huawei, Oppo ... devices from restarting Foreground Service ?
Which is the case with WhatsAPP, Messenger, Instagram and others.
It's a tricky question since it really depends on the vendor. There is a site which document and rank the vendor according to "how bad" they're handling services and processes. From the site:
...With Android 6 (Marshmallow), Google has introduced Doze mode to the base Android, in an attempt to unify battery saving across the various Android phones. Unfortunately, vendors (e.g. Xiaomi, Huawei, OnePlus or even Samsung..) did not seem to catch that ball and they all have their own battery savers, usually very poorly written, saving battery only superficially with side effects.
The solutions differs from vendor to vendor and from ROM version to another.
For example for Huawei you can overcome the issue in Huawei P20, Huawei P20 Lite, Huawei Mate 10 by Phone settings > Battery > App launch and then set your app to “Manage manually” and make sure everything is turned on. Also for reliable background processes you may need to uninstall PowerGenie (which is a power mgmt. application by Huawei). On the other hand for EMUI 9+ devices you'll have to uninstall PowerGenie via adb

Android use of mobile data when in background

I have developed a hybrid app running on Android, that successfully monitors the users location and displays it to the user as a moving icon on a map. This part of the app is all written in javascript and works inside a webview. The webview also communicates with my remote server to share the user's location with other users of the same app.
Up until Android Nougat this all works even when the app is backgrounded for several days. When the user returns to the app they can see where they have been with timestamps at each point. And all the other app users can see where everyone is, even if they are no actively using the app.
From Android Oreo onwards, I had to move the location tracking to a background service to get it to continue in the background and I have tested this to be still working fine even with the app in the background for a long period. Returning to the app, the user can still see where they have been. However the remote communications to the server, on Android Oreo and later, cease after approximately 2 minutes in the background.
Please could someone explain why this is, and what I could (if anything) do about it?
What is the restriction that I am running into and where is it documented on Android developer? I have set the app as not to be limited in settings/network/data saver and this makes no difference.
Would it make a difference if I replaced the webview XMLHttpRequest with similar code in background service, using volley or something similar?
All help very much appreciated.
Although I have not discovered what restriction I am running foul of, I have found that by moving the http request from the web view to the background service using volley, the server continues to be updated whether or not the application is in the foreground.
Only tested so far on Android 8,9 and 10 in the emulator. Testing soon on a real device

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...

How to have an android phonegap app allways running

I have an Android app (internal for my company, not public) developed using JQM and Phonegap.
The app check each 15 minutes if the company server have some news for the device (1 device = an employee).
But it only works if the device is not in sleep mode.
I would like at least be able to do the same as whatsapp and other apps, send a little message to the notification area and/or shows a little window, sounds a beep...
I can do some of this (as shows a window, sounds a beep) but only if the device is running in visible (not sleep) mode.
Then my question is:
How to have an android phonegap app that is always running, or at least run each x minutes?
I this is not possible... Is possible then create an "mini" real native app only for this purpose, thus "call" to my app each x minutes?
Thanks,
Guillermo, Spain.
link http://www.tipsfromsiliconvalley.com/2013/07/06/create-a-service-on-android-with-phonegap-application/
There is this article on how to create a service on Android with Phonegap which gives some good information on your problem.
It's using a great plugin in order to build a background service with phonegap easily. But you can't use JS though
I didn't find a way to make JS to run in the Background. BUT you can pass parameters from Java to JS and vice versa with the plugin...which is pretty useful. You would still need to rewrite your JS code in Java though.
you could create a service that calls a javascript callback? For example, you could have a service in Java code that when it receives a text message it calls a javascript callback function to execute some JS code? That would be perfect. plugin that seems to create a service and call Js code:
https://github.com/marknutter/GCM-Cordova

Categories

Resources