I found a solution for some regular background activity!


#1

Are you trying to make an app that does something every x minutes, even when the app is in the background and/or the screen is turned off… tried backgound-mode plugin but it only works reliably when the phone is plugged in… did you ever found a solution to this?

Made my own solution, https://github.com/boltex/cordova-plugin-powermanagement

I modified the regular power management plugin : I changed SCREEN_DIM_WAKE_LOCK to PARTIAL_WAKE_LOCK

here’s how i use it along with the background mode plugin so the app is never in background and always running as a service…:

if( ionic.Platform.isAndroid() ){
cordova.plugins.backgroundMode.enable();

window.powerManagement.dim(function() {
  console.log('Wakelock acquired');
}, function() {
  console.log('Failed to acquire wakelock');
});
window.powerManagement.setReleaseOnPause(false, function() {
  console.log('setReleaseOnPause successfully');
}, function() {
  console.log('Failed to set');
});

}

How to always run app on background even if it was closed? (SERVICE)
Cordova Background mode plugin
How to run app in background even if it is closed like whatsapp
#2

Hello there!
Great solution you saved my day! Thank you!
One more question:
Is it available push OK button on USSD response popup on android ?
For example call to “*100#” and hit OK programmatically ?
Thanks for answer!


#3

hi,
i have tried this but it works only at first time,next time app completely closed.is there any thing else to set in the code.at first time app is moved into cached app area.after that when i closed the app, it completely closed.


#4

You have both plugin installed in the app? ( my version of power management plugin AND background mode plugin ) ?

and you setup as in my example? I guess i should make a demo app… i will try to do one this week-end.


#5

Hi boltex,

I got an app that has to run all the time and survive reboots. The app does an alarm at sunrise time every day. That’s the whole point of the app. Set it and forget it until that preference run all the time is unchecked.

Since the sunrise changes everyday, my app has to compute the next sunrise and when that time comes boom, vibrate the phone and play a notification.

I got a js timer on the app that checks every minute to see how much time left and when it is the last minute, it updates itself to run every second so it can display 59, 58, 57… when it is 0, we hear the alert!

When the app is on, this is not a problem.
When the app goes to background, it seems to be working with just the “backgound-mode plugin”.
But I have no idea how to put the app in the background after a complete shutdown or battery run out!

Would your solution work for me?


#6

just with the “background-mode” plugin only?

I thought i only needed that while I programmed with my device plugged in via USB to debug… I noticed Android started to close the app when in background mode only while NOT plugged to computer via usb. That is why I modified the power management plugin to get everything working all the time!

About the reboot : I never tried to do that !!! but i just did a google search for “cordova app start at reboot” and found this : https://github.com/ToniKorin/cordova-plugin-autostart

Did you try that? please tell me what you think about it :smile:


#7

I have installed both the background mode and the power management plugin. I want to call a function daily on a spcific time. It works when the app in background. If i closed the app, the background service not running. The background service running only when the app in background.


#8

Please be more precise, what do you mean exactly?


#9

I am developing an employee management app. In that i have to trigger on e function at 9 O’Clock to signin automatically.It should work even the app not running. To achieve this i want to run the app in background.


#10

Yes, the app needs to be in the background. If you completely close the application, (By killing it in the app manager) then it will not do anything.


#11

@boltex … I’m trying to do a upload of the photo and some information to server like the way of uploading a photo in facebook…but while uploading ,if the app is closed it is failed…Can you please help me how to achieve this even when they close the application while uploading. your plugin is working when the app is in background. But i want to run that even when the app is close


#12

@boltex Could you provide a full example? Thank in advance.


#13


??? any solution ???


#14

Hi there

When I am using this code in my app its giving me below error

Warning: Uglification failed.
Unexpected token punc «;», expected punc «,».

Its showing at the 2nd last line of the code!
Any idea why its giving syntax error?


#15

hello @simo i fetching same issue did you solved it ???
please help me… thanks


#16

hello @nakulkundaliya i modified the java files in this plugin “cordova-plugin-mauron85-background-geolocation” to achieve my goal but just in android.
if u want this plugin after modification i will be uploaded for you.
sorry for bad english :stuck_out_tongue:


#17

Thanks for replay
Can you paste modification code here???


#18

plugin : https://ufile.io/2a922
uncompress this file in the folder “com” in cordova-plugin-mauron85-background-geolocation plugin
Most of the changes in the file LocationService.java

Any help I am in the service