Open ahsanhabib23 opened 5 years ago
I founded the solution at https://github.com/katzer/cordova-plugin-background-mode/issues/430
disableBatteryOptimizations
I founded the solution at #430
disableBatteryOptimizations
not working
I have the same problem !
Solução crie uma service com uma notificação passos!!!!! index.js >> receivedEvent, onDeviceReady
antes cordova.plugins.backgroundMode.setDefaults({ title: "title", text: "text", icon: 'icon', // this will look for icon.png in platforms/android/res/drawable|mipmap color: "6E10A0", // hex format like 'F14F4D' resume: false, silent: false, hidden: false, bigText: false, })
aqui cordova.plugins.backgroundMode.enable(); antes cordova.plugins.backgroundMode.onactivate = function () { cordova.plugins.backgroundMode.disableWebViewOptimizations(); }; cordova.plugins.backgroundMode.ondeactivate = function () { alert('teste') };
aqui cordova.plugins.backgroundMode.disableBatteryOptimizations();
plugin.mxl add permission
inicie o service com uma notificação pegue parte do codigo plugin powemanger e inclua em seu service ele vai trabalha para servir cordova.plugins.backgroundMode para manter ele sempre ativo! abraços!!!!! testado Android 8 e Android 9 rodando aqui 24hs por dias! vlw
Solução crie uma service com uma notificação passos!!!!! index.js >> receivedEvent, onDeviceReady
antes cordova.plugins.backgroundMode.setDefaults({ title: "title", text: "text", icon: 'icon', // this will look for icon.png in platforms/android/res/drawable|mipmap color: "6E10A0", // hex format like 'F14F4D' resume: false, silent: false, hidden: false, bigText: false, })
>>> aqui cordova.plugins.backgroundMode.enable(); >>> antes cordova.plugins.backgroundMode.onactivate = function () { cordova.plugins.backgroundMode.disableWebViewOptimizations(); }; cordova.plugins.backgroundMode.ondeactivate = function () { alert('teste') }; >>>> aqui cordova.plugins.backgroundMode.disableBatteryOptimizations();
plugin.mxl add permission
inicie o service com uma notificação pegue parte do codigo plugin powemanger e inclua em seu service ele vai trabalha para servir cordova.plugins.backgroundMode para manter ele sempre ativo! abraços!!!!! testado Android 8 e Android 9 rodando aqui 24hs por dias! vlw
Haa ótima ideia :) @ahsanhabib23
For me not working :( !!
if i set targetSdkVersion="26" or targetSdkVersion="27" this plugins works, but the Google not will accepted API smaller than 28 !! and with targetSdkVersion="28" not working :( !
Do you still have the issue if you use this plugin? https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
@TDola , I cant even get the plugin from that url.
@utan in this url, have a description of instalation
@TDola , Yes I indeed ran the installation procedure , it failed with the following:
`Failed to fetch plugin https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background via registry. Probably this is either a connection problem, or plugin spec is incorrect. Check your connection and plugin name/version/URL. Error: npm: Command failed with exit code 1 Error output: npm ERR! path git npm ERR! code ENOENT npm ERR! errno ENOENT npm ERR! syscall spawn git npm ERR! enoent Error while executing: npm ERR! enoent undefined ls-remote -h -t https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background.git npm ERR! enoent npm ERR! enoent npm ERR! enoent spawn git ENOENT npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent
npm ERR! A complete log of this run can be found in: npm ERR! /home/utan-dev/.npm/_logs/2019-08-20T13_23_10_949Z-debug.log `
Opps disregard, forgot I switched to Ubuntu and didn't have Git installed yet..
@utan do you tryed to create a simple installation and testing this plugin? i haved this error, but, when i create a new app with same version, works !
Ok, the plugin got installed.. But It won't stay connected once go into background mode..
I have cordova @9.. any other way to make this work..?
@utan cordova 8.1.2 (cordova-lib@8.1.1)
@Flavioamorim , so with this cordova 8.1.2 works?
Works fine in cordova 9, be sure to set the disable battery and webview optimizations, otherwise Android Pie shuts down anything that runs too long. These features were fixed in the fork The BosZ made
Hi` @TDola I have that! do you mean disableWebVIewOptimization:method ?
`js cordova.plugins.backgroundMode.enable();
cordova.plugins.backgroundMode.on('activate', function() { cordova.plugins.backgroundMode.disableWebViewOptimizations(); }); `
yes that should be all that's needed. If its not working as it should, post a new issue here https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background
@TDola , I will, I had it wrapped in a timeout of 500 mils .. will test without it.. and see.
You can fix that with cordova-plugin-background-geolocation, if that's an option for you.
Same issue here, working for 5min on a Xiaomi device with Android One.
I also tried to add a setInterval
which attempts to do a cordova.plugins['backgroundMode'].moveToForeground()
but without success...
Same issue here, the app stops after 5 minutes. Tested every sugestion above..
@andreddosantos did you try https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background ?
Yes while in background i used to call a sqliteplugin to persist some coordinates and now after five minute the calls to the sqlite just pile in the callstack
I have the same problem, after 5 minutes the application stops, on android 8 and 9.
Anyone already have any solution?
Not sure, my own usage is designed to give up after 15 minutes anyways as to not kill the users battery. But in theory I am calling configure a lot. I use the notification text as a progress indicator. So the frequent updates, once per 20 seconds roughly, might be tricking Android into keeping it alive?
My usage is basically this: On app pause event -> Check a queue, if anything important is in the queue, activate background mode As queue runs, it updates background mode with config. The queue is essentially a setTimeout that recursively calls itself and burns down a list of tasks in a sqllite database, updating as it goes, and uploading a file. Every successful loop causes the config call. If the queue runs out of important tasks, even if there is still more tasks in it, it tells background mode to shut down. On some phones the app keeps going anyways, on others it stops immediately.
In the case of iOS, I use background fetch instead. It's the same basic principal, except it shuts itself down after 25 seconds as to not use too much time on iOS and risk the OS killing the process.
Background mode is broken in iOS and won't be accepted to the app store anymore
Not sure, my own usage is designed to give up after 15 minutes anyways as to not kill the users battery. But in theory I am calling configure a lot. I use the notification text as a progress indicator. So the frequent updates, once per 20 seconds roughly, might be tricking Android into keeping it alive?
My usage is basically this: On app pause event -> Check a queue, if anything important is in the queue, activate background mode As queue runs, it updates background mode with config. The queue is essentially a setTimeout that recursively calls itself and burns down a list of tasks in a sqllite database, updating as it goes, and uploading a file. Every successful loop causes the config call. If the queue runs out of important tasks, even if there is still more tasks in it, it tells background mode to shut down. On some phones the app keeps going anyways, on others it stops immediately.
In the case of iOS, I use background fetch instead. It's the same basic principal, except it shuts itself down after 25 seconds as to not use too much time on iOS and risk the OS killing the process.
Background mode is broken in iOS and won't be accepted to the app store anymore
Did you found a Solution?
Not sure, my own usage is designed to give up after 15 minutes anyways as to not kill the users battery. But in theory I am calling configure a lot. I use the notification text as a progress indicator. So the frequent updates, once per 20 seconds roughly, might be tricking Android into keeping it alive? My usage is basically this: On app pause event -> Check a queue, if anything important is in the queue, activate background mode As queue runs, it updates background mode with config. The queue is essentially a setTimeout that recursively calls itself and burns down a list of tasks in a sqllite database, updating as it goes, and uploading a file. Every successful loop causes the config call. If the queue runs out of important tasks, even if there is still more tasks in it, it tells background mode to shut down. On some phones the app keeps going anyways, on others it stops immediately. In the case of iOS, I use background fetch instead. It's the same basic principal, except it shuts itself down after 25 seconds as to not use too much time on iOS and risk the OS killing the process. Background mode is broken in iOS and won't be accepted to the app store anymore
Did you found a Solution?
To it only working for 5 minutes? Far as I can tell, as long as there is activity to the notification, it keeps working. Try calling configure in a setTimeout loop to update the notifications periodically and see if it still stops running after 5 minutes.
@megadrazz
Your solution worked well for me. But all of a sudden it does not work. Additionally, whenever I go to the background, I console.log some data inside cordova.plugins.backgroundMode.onactivate and cordova.plugins.backgroundMode.ondeactivate. So whenever I go back and forth, nothing is printing
same problem here. 5 min and no more XHR calls from the background. still getting geo location updates but the call to the server is blocked by the system. any solution ?
do you request android.permission.ACCESS_BACKGROUND_LOCATION in your MainActivity ?
If you can, you might want to reconsider tracking in the background. https://developer.android.com/about/versions/11/privacy/location https://developer.android.com/training/location/permissions#request-background-location As noted above, google is cracking down on it. Your app must now either request foreground, or background location access.
You can call the wakeUp method in a given interval to keep the app awake.
const timer = 4*60*1000; // four minutes
this.backgroundMode.enable();
this.backgroundMode.on('activate')
.subscribe(()=>{
setInterval(()=>{
this.backgroundMode.wakeUp();
this.backgroundMode.moveToForeground();
},timer);
});
@katzer
The App is running for almost 5 minutes at the background. After that, it stops working. If I resume then it starts again.
I have tried several solutions. I have also used the plugin https://github.com/DavidBriglio/cordova-plugin-foreground-service and added
cordova.plugins.foregroundService.start('GPS Running', 'Background Service', 'myicon', 3, 10);
cordova.plugins.backgroundMode.disableBatteryOptimizations();
cordova.plugins.backgroundMode.disableWebViewOptimizations();
But it did not work. I also tried with Cordova power management. This is my GitHub repo https://github.com/ahsanhabib23/testBackgroundIonic3 where the issue has been reproduced.
I am using the fork version. Most added the library by running this command
cordova plugin add https://github.com/katzer/cordova-plugin-background-mode --nofetch
I know there is an existing open issue. But still posting because comments from there did not help.