简体   繁体   中英

Why is the cordova-local-notification-plugin not working (Phonegap, Android)?

I built a Phonegap App with this plugin , and it seems, as it is used in the app: 在此处输入图片说明

The config.xml :

<plugin spec="https://github.com/katzer/cordova-plugin-local-notifications.git#b8f358e" />

But when I try to send local notifications it looks like the plugin doesn't work. I tried this:

    document.addEventListener('deviceready', function () 
    {
        alert(1);


        cordova.plugins.notification.local.schedule({
           id:      1,
           title:   'Some Timer',
           message: 'Some Message'
        });

        alert(2);

    }, false);

But only the first alert is working, that's why I think that the plugin isn't working right. So how can I build an App to send local notifications?

Thank you very much :-)


cordova -v 9.0.0 (cordova-lib@9.0.1)

cordova plugin ls cordova-plugin-whitelist 1.3.4 "Whitelist"

But as shown above, I added the local.notification plugin in the config.xml, and the Adobe Phonegap Build webpage, says that the plugin is used.

cordova platform ls Installed platforms: android 8.0.0 browser 4.1.0 Available platforms: electron ^1.0.0 ios ^5.0.0 osx ^5.0.0 windows ^7.0.0


PS: I posted a similar question two days ago, but I edited it to specify my question.

Thanks for sharing the file. I was able to run successfully your app and the notifications works each time. However, you need to edit the code as below

For notifications without ID param

cordova.plugins.notification.local.schedule({
    title: 'My first notification',
    text: 'Thats pretty easy...',
    foreground: true
});

For notifications with ID param, ID should be unique

cordova.plugins.notification.local.schedule([
    { id: 1, title: 'My Second notification' },
    { id: 2, title: 'My Third notification' }
]);

Index.js

var app = {
  // Application Constructor
  initialize: function() {
    document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
  },
  onDeviceReady: function() {
    this.receivedEvent('deviceready');
  },
  receivedEvent: function(id) {    
    oneNotification();
    multipleNotification();
  }
};

app.initialize();

function oneNotification() {
  cordova.plugins.notification.local.schedule({
    title: 'My first notification',
    text: 'Thats pretty easy...',
    foreground: true
  });
}

function multipleNotification() {
  cordova.plugins.notification.local.schedule([{
      id: 1,
      title: 'My Second notification'
    },
    {
      id: 2,
      title: 'My Third notification'
    }
  ]);
}

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