How to have an android phonegap app allways running - android

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

Related

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

Nativescript application running on background automatically open in foreground

I have a nativescritp app, which receive phone calls.
When the app is not running on foreground, it still receives the calls, which is fine.
What I need to do is to "load" / "run" / "show" the application on the screen, so the user can answer the phone call or decline it.
It may not be quite straight forward as building an app and there are no ready made plugins available to achieve this.
For iOS you will have to implement CallKit and for Android you will have follow the set of procedures explained here.
FYI, with iOS your normal code won't run any longer if app is minimised. With Android you will have to implement the android.telecom.ConnectionService as explained in the link above, refer onShowIncomingCallUi() for showcasing UI for the call.
If you are not proficient with marshalling native code (iOS & Android) then I would suggest you to start there.

How to run codes after the Ionic App has exited?

I'm using Ionic 2 to develop my Android project. I need to send a notification while have detected my iBeacon devices nearby even if my App has been exited.
The following plugins does not work for me:
Background mode: Works while App has been put in background. But what I need is to send notifications while the App has been killed.
Bgs: Doesn't work for me. The founder didn't try Ionic 2 project, so that he cannot figure out what may be the problem. But I do create a project here.
Just hope someone can tell me if it's possible to create an independent background service to retrive data. So that I can stop wasting time.

Run mobile web application in the background as a service

I am working on a HTML5 mobile web application that runs in browser. I want this app to receive server sent push notifications even when the browser/web app is closed. For that reason, I would want my mobile web app to run in the background once visited. I mean I will store some code on mobile maybe cache etc. So the question is that is it possible to run mobile web app as a service on mobile device?
Yes, in iOS, you can let your web application run in background (when it is closed). You have to give some settings to your application. However, in background, the UI threads is suspended, all commands in UI thread will be cached, until you open your application again. So remember to process your services in background threads, else they will be stucked with UI thread.
In Android, you can even create a service (without interface) and let it execute separately from your main application.
For another platform, I don't know the answer.
On iOS you can set a web page to run as a web app. There is even an SO tag for iphone standalone web apps, and the overview explains it nicely.
Here is the equivalent for Android - Add to homescreen

Executing Javascript in background using Phonegap

I've created an application that will need to fire Javascript events every "X" minutes. I'm using phone gap build to deploy on Android/iPhone/Blackberry, but I'm of course stuck, as the Javascript timer doesn't fire in the background (when they minimize the app). I was wondering if Phonegap had some sort of ability to fire Javascript events while the app is running in the background.
Or is there ANY way to accomplish this easily across these major phones? I just need to fire an ajax call with the geolocation info from the phones.
Yes you can do it, there's a PhoneGap plugin that does exactly what you need:
PhoneGap + Background.js
https://github.com/jocull/phonegap-backgroundjs
Be careful configuring your config.xml
Currently, phone gap doesn't have this as an option. There are many requests out there for this sort of thing, but I think people are getting tripped up by the TOS for background events for iOS. Regardless, a phone gap plugin would do it as #Chase mentioned, but of course that requires native code writing.
I'm assuming you're wanting to push geo locations every x seconds/minutes so that your server knows where the phone is at any point in time (as long as the app is open or minimized)? That's one limitation of Loopt, is that it can't grab those locations in the background - hence the whole 'ping' action in the app.

Categories

Resources