Notifications only works if being triggered at the current time, not a time in future!
See original GitHub issueWARNING: IF YOU IGNORE THIS TEMPLATE, WE’LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!
Last year, I have used this plugin for an Ionic v3 application (which I no longer have the access to the source code so no idea which version it was) and it worked just great. However, now when I tried to used it in another new one, it doesn’t operate as it should. In short, I cannot make local notification comes at a specific time in the future, only at the current moment, there is no error log shown when calling the plugin.
Any help would be much appreciated.
Your Environment
Plugin: cordova-plugin-local-notification 0.9.0-beta.2 “LocalNotification”
Ionic: Ionic CLI : 5.2.5 (C:\Users\hoangN\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.1.8
Cordova: Cordova CLI : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 8.1.0 Cordova Plugins : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 1.1.1, (and 13 other plugins)
Utility: cordova-res : 0.8.0 (update available: 0.8.1) native-run : 0.2.9
System: NodeJS : v10.16.3 (C:\Program Files\nodejs\node.exe) npm : 6.9.0 OS : Windows 10
Expected Behavior
Notifications should come at the time specified in the trigger param.
Actual Behavior
Notifications only come at current moment, no future triggering.
Steps to Reproduce
This is the simplified piece of code that I’m using in order to demonstarte this issue, I’ve created 2 button to fire notifications, one is for current moment, one is for 2 minutes later from that.
setLocalNotiNow() {
let promise = new Promise(() => {
let currdate = moment().format('YYYY-MM-DD HH:mm:ss');
let currentMoment= moment(currdate,'YYYY-MM-DD HH:mm:ss' )
console.log(currentMoment.toDate())
this.localNotifications.schedule({
text: 'Xin vui lòng đến đúng lịch để chúng tôi có thể phục vụ bạn tốt hơn.',
trigger: { at: currentMoment.toDate() },
led: 'FF0000',
sound: null,
priority:1,
foreground:true
});
});
return promise;
}
setLocalNotiLater() {
let promise = new Promise(() => {
let currdate = moment().format('YYYY-MM-DD HH:mm:ss');
let currentMoment= moment(currdate,'YYYY-MM-DD HH:mm:ss' )
let time = moment.duration("00:02:00");
currentMoment.add(time)
console.log(currentMoment.toDate())
this.localNotifications.schedule({
text: 'Xin vui lòng đến đúng lịch để chúng tôi có thể phục vụ bạn tốt hơn.',
trigger: { at: currentMoment.toDate() },
led: 'FF0000',
sound: null,
priority:1,
foreground:true
});
});
return promise;
}
Context
What were you trying to do?
Debug logs
Include iOS / Android logs
- ios XCode logs
- Android: $ adb logcat
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:19
Top GitHub Comments
I finally found some time to investigate into this, and it seems that my fix is solving this issue. Here is an explanation why it’s not working.
https://github.com/katzer/cordova-plugin-local-notifications/blob/caff55ec758fdf298029ae98aff7f6a8a097feac/src/android/notification/Notification.java#L217-L243
The first line decides if the Notification Intent is triggered immediately or if its a PendingIntent added to the AlarmManager.
The AlarmManager then did not wake up, and fired the notification, because the following Receivers were not added to the AndroidManifest.xml
https://github.com/katzer/cordova-plugin-local-notifications/blob/caff55ec758fdf298029ae98aff7f6a8a097feac/plugin.xml#L103-L135
I fixed this in my fork:
https://github.com/katzer/cordova-plugin-local-notifications/compare/master...m0dch3n:master
So the solution which worked for me is:
It seems this plugin is also no longer maintained, and JFYI, I will neither maintain my fork, unless I find specific problems to my apps.
BTW: I think it has nothing todo with the
smallIcon
, or array solution, but you can correct me… I suppose it only worked during your debug session, because you stopped long enough in your Breakpoint, so thatbecame true…
I have had the same issue. Actually it worked for me few weeks ago and then it stopped working randomly. The notifications worked only when triggered instantly.
But I’ve found a solution! At least for me. The code below was missing on my AndroidManifest.xml. I have no idea why, maybe another plugin messed it up (probably firebasex with his push notifications?)
Anyway just add it to your manifest and it will start working again.