Android cordova插件本地通知在应用程序被终止后单击事件

Android cordova插件本地通知在应用程序被终止后单击事件,android,cordova,notifications,Android,Cordova,Notifications,我在这方面发现了很多老问题,但我没有找到一个明确的答案,在应用程序被终止后,让本地通知单击事件起作用。如果应用程序处于活动状态或处于后台,则通知将起作用。为了进行测试,我编写了以下代码 app.initEvents = function() { "use strict" ; var fName = "app.initEvents():" ; app.consoleLog(fName, "entry") ; cordova.plugins.notificatio

我在这方面发现了很多老问题,但我没有找到一个明确的答案,在应用程序被终止后,让本地通知单击事件起作用。如果应用程序处于活动状态或处于后台,则通知将起作用。为了进行测试,我编写了以下代码

app.initEvents = function() {
    "use strict" ;
    var fName = "app.initEvents():" ;
    app.consoleLog(fName, "entry") ;


    cordova.plugins.notification.local.isPresent(1, function (present) 
    {
        if (! present) {
            var d = new Date();
            d.setMinutes(d.getMinutes() + 2);
            cordova.plugins.notification.local.schedule({
                id: 1,
                title: "Test message",
                message: "Message body",
                date: d
            });
        }
    });

    cordova.plugins.notification.local.on("click", function (notification, state) {
        alert(notification.id + " was clicked -> app.Ready");
    }, this);

    var el, evt ;

    if( navigator.msPointerEnabled || !('ontouchend' in window))
        evt = "click" ;
    else
        evt = "touchend" ;

    app.hideSplashScreen() ;

    app.consoleLog(fName, "exit") ;
} ;
document.addEventListener("app.Ready", app.initEvents, false) ;
发生的情况是,通知已安排,并在2分钟后显示。如果应用程序在通知仍被触发的同时被终止,但单击事件未被处理,通知将再次安排。因此,我假设通知在单击后被清除,并且由于app.ready事件稍后得到处理,因此无法处理单击事件


有没有办法让这一切顺利进行?我使用的是CLI 6.5和0.8.4版本的插件。我只在安卓7.1.1上进行了测试。

为了确保事件监听器将启动,您必须将其放置在设备ADY中,例如:

document.addEventListener('deviceready', onDeviceReady, false);

const onDeviceReady = () => {
  window.cordova.plugins.notification.local.on('click', (notification, args) => {
      alert(notification.id + " was clicked -> app.Ready");
  });
}

但是,请确保将其放置在调用
DeviceRady
之后,否则,它可能无法正常工作。

要确保事件侦听器将启动,您必须将其放置在
DeviceRady
中,例如:

document.addEventListener('deviceready', onDeviceReady, false);

const onDeviceReady = () => {
  window.cordova.plugins.notification.local.on('click', (notification, args) => {
      alert(notification.id + " was clicked -> app.Ready");
  });
}

但是,请确保将其放置在调用
设备ADY
之后,否则,它可能无法正常工作。

您找到上述情况下的解决方案了吗?您找到上述情况下的解决方案了吗?