Cordova Background mode plugin

i have issue with Cordova Background mode plugin use it but it doesn’t prevent app from sleeping ?

Should it do that?
What does “sleeping” mean here?
What exactly did you implement?

1 Like

here my problem:

app does’t work after +/- 3 hours after the screen is turned off.
i have a issue with an ionic 3 app, my app use a timer to check something on server every 3 seconds so that work fine, but when the screen is turned off after +/- 3h my app doesn’t work anymore it stop sending request, i think it enter in Doze and App Standby MODE AND system prevent it from using network and other resources.

after some search on forum i found this :

i integrated the some code in my app here is the code:

initializeApp() {
this.platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
this.statusBar.styleLightContent();
this.splashScreen.hide();

        //config language
        this.getAppLanguage();
  
        this.backgroundMode.enable();
        this.powerManagement.dim().then(() => {
          console.log('-------$$------- Wakelock acquired -------$$-------');
        })
        .catch(() => {
          console.log('-------$$------- Failed to acquire wakelock -------$$-------');
        });

        this.powerManagement.setReleaseOnPause(false).then(() => {
           console.log('-------$$------- setReleaseOnPause successfully -------$$-------');
        })
        .catch(() => {
             console.log(' -------$$------- Failed to set -------$$-------');
        });

    });
}

Why should it?

This sounds like a sure way to drain the battery, fast - and give a terrible customer experience.

Why not just send a push notification to the device from the server if something relevant changes?

1 Like

i dont that will work so, because after +/- 3 or 4 hours the screen is turned off my smartphone disconnect from wifi auto, and reconnect to wifi auto after touching the screen to turn on

If your smartphone disconnects from the internet, a process running in the background of course also will not be able to connect to the internet - so this won’t work as well.

But usually smartphones reconnect to the wifi regularly to get new push notifications. Push notifications were built for exactly the use case when information from a server should be available on a device.

1 Like

so i understand that, so i tried power-management plugin and background-mode plugin but it’s not doing the trick so, i will try push notifications.
thnks brother

hi, i am having similar issue. the app we created is an alerts app, users post alerts on the map. if another user creates a notification filter for a specific type of alert within say 100 km of their location we want to show a local notification.

the way we handle this is using backgorund mode. we sync all the alerts in the background and whatever matches the filter we show as local notification.

now, this doesnt always seem to work reliably. unless the phone is connected to the battery. i also cant use push notification because the user is mobile which means i need to send the location of the user to the server. if the app is in the background this is an issue.

has anyone solved this issue? is there a work around?

@Sujan12, i am facing same issue but these notifications are based on the user’s location so even for push notifications to work i will need to send user location to the server all the time and with background mode this seems to not work all the time unless the phone is conntected.

@technica Did you found a solution?
Can we use this with ionic?
https://github.com/katzer/cordova-plugin-background-mode

1 Like

j’ai pas trouvé la solution a l’époque et j’ai abandonné ionic j’ai redeveloper tout en java

Merci :slight_smile:

Hi @Sujan12, Did you found a solution?

welcome :slight_smile: