简体   繁体   中英

how can i run cordova app even user close the app

want create app cordova and ionic for android to alaram in some times like 2:50 and I want program run even close the program I use katzer/cordova-plugin-background-mode plugin, but when I close program, it be close and don't still run in background this is code Example I used:

document.addEventListener('deviceready', function () {

  cordova.plugins.backgroundMode.setDefaults({
    title:  'TheTitleOfYourProcess',
    text:   'Executing background tasks.'
  });

  // Enable background mode
  cordova.plugins.backgroundMode.enable();

  // Called when background mode has been activated
  cordova.plugins.backgroundMode.onactivate = function () {
    // Set an interval of 3 seconds (3000 milliseconds)
    setInterval(function () {
      var dd = new date();
      var h = dd.getHours();
      var m = dd.getMinutes();
      if(h == 2 && m ==50){
        alert("2:50");
      }
    }, 3000);
  }
}, false);

how can I make app still run even user close the program like , alarm clock or some program reminder ?

将此行添加到您的config.xml以启用后台活动

<preference name="KeepRunning" value="true"/>

no need to use background-mode plugin. use this

https://github.com/vasani-arpit/cordova-plugin-local-notifications

it based on katzer's local-notification plugin

here is the example repo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM