cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

In android, background mode code is not working

Open iomJvaranam opened this issue 8 years ago • 14 comments

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/"

iomJvaranam avatar Jan 10 '18 13:01 iomJvaranam

Same for me with vanilla cordova. Background mode is not working on Android

Does anybody know a background mode plugin that works on android?

pixelquadrat avatar Jan 11 '18 12:01 pixelquadrat

I got the solution Try this.backgroundMode.on('activate').subscribe(() => { this.backgroundMode.disableWebViewOptimizations(); // run your code here });

iomJvaranam avatar Jan 11 '18 13:01 iomJvaranam

As I'm on vanilla cordova, unfortunately your code snippet is not working for me. :-(

pixelquadrat avatar Jan 11 '18 14:01 pixelquadrat

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.

pixelquadrat avatar Jan 11 '18 16:01 pixelquadrat

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

iamisti avatar Jan 14 '18 08:01 iamisti

Check my pull request if you have no solution https://github.com/katzer/cordova-plugin-background-mode/pull/359

vgichar avatar Feb 13 '18 14:02 vgichar

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

KhimGurung avatar May 11 '18 08:05 KhimGurung

guys, any solution for ionic3 now?

TonyLuo avatar Jun 26 '18 08:06 TonyLuo

having issue on this as well. any solution?

glenngsanchez avatar Nov 16 '18 06:11 glenngsanchez

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

harlenn avatar Dec 18 '18 03:12 harlenn

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

theCrius avatar Jan 18 '19 21:01 theCrius

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

MInesGomes avatar May 09 '19 11:05 MInesGomes

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);
    });

maikonigor avatar Jun 02 '21 20:06 maikonigor

Use this plugin ::

https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/

GhoshWorld avatar Jul 20 '21 03:07 GhoshWorld