In android, background mode code is not working
Android app in background code is not working, while I enabled the background code in ios the entire code is executing as normal, but on Android, nothing happening. I was using this plugin in ionic 3 application "https://ionicframework.com/docs/native/background-mode/"
Same for me with vanilla cordova. Background mode is not working on Android
Does anybody know a background mode plugin that works on android?
I got the solution
Try
this.backgroundMode.on('activate').subscribe(() => { this.backgroundMode.disableWebViewOptimizations(); // run your code here });
As I'm on vanilla cordova, unfortunately your code snippet is not working for me. :-(
Ok, I got it working with the following code:
cordova.plugins.backgroundMode.on('activate', function() { app.onModeActivated; cordova.plugins.backgroundMode.disableWebViewOptimizations(); cordova.plugins.backgroundMode.moveToBackground(); /* YOUR CODE GOES HERE */ });
But it stops working when the screen is switched off... and yes I told Android to execute the app when the screen is off... But maybe thats just the geolocation part that does not work with switched off screen.
are u guys using ionic 2 or 3? Cause it just doesn't work on 3. I need better example when it's used in the app.ts file or in a controller...
Check my pull request if you have no solution https://github.com/katzer/cordova-plugin-background-mode/pull/359
@iamisti any solution for background processing in ionic3? I am trying to show notification when user reached near some location. When i install background mode plugin my app just stop working in browser emulator in all platform it just stop no any error.
guys, any solution for ionic3 now?
having issue on this as well. any solution?
@KhimGurung
@iamisti any solution for background processing in ionic3? I am trying to show notification when user reached near some location. When i install background mode plugin my app just stop working in browser emulator in all platform it just stop no any error.
Probably a bit late for you, but a number of the cordova plugins will need to be run on a physical device as they won't work as expected on a browser emulator.
Given that this one is related to background mode and isn't applicable to the browser emulator I'm guessing that is why it wasn't working for you.
Not a problem with the browser emulator:
Testing on an android device (honor 8x, Android 8.1.0), background mode not working.
Development environment:
Ionic:
ionic (Ionic CLI) : 4.7.0
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.1
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 7.1.4, browser 5.0.4, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.3.1, (and 11 other plugins)
System:
Android SDK Tools : 26.1.1
NodeJS : v10.9.0
npm : 6.2.0
OS : Windows 10
It is working in my app :-) https://play.google.com/store/apps/details?id=nl.gotop.nms
You can see here the code https://github.com/katzer/cordova-plugin-background-mode/issues/400#issuecomment-484077499
you can call the wakeUp method at a given time.
const timer = 4*60*1000; // four minutes
this.backgroundMode.enable();
this.backgroundMode.on('activate')
.subscribe(()=>{
setInterval(()=>{
this.backgroundMode.wakeUp();
this.backgroundMode.moveToForeground();
},timer);
});
Use this plugin ::
https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/