The notifications will not trigger when app is closed(killed) and will be triggered after opening the app
See original GitHub issueI’m implementing a basic app for reminding a person to take her pills. I need to have something like an alarm clock. I need to show notifications to her with positive sentences. I need your help to achieve this. I hope you help and I appreciate it in advance.
Your Environment
- Plugin version:
- Platform: 0.9.0-beta.3
- OS version: Android 9
- Device manufacturer / model: Smasung S8
- Cordova version (
cordova -v
): 9.0.0 (cordova-lib@9.0.1) - Cordova platform version (
cordova platform ls
): android 8.1.0 - Plugin config : [if you mean config.xml, I didn’t change anything in it. It is too long to append here]
- Ionic Version (if using Ionic)
Expected Behavior
Based on my understanding that maybe is false #750, when a notification is scheduled for the future, it should be displayed even when the app is closed or killed.
Actual Behavior
the notifications are triggered when the app is open or is in the background, but when I close the app (I do this by clear all in the history) the notifications will not trigger and when I open the app again all of the scheduled ones triggered at once.
Steps to Reproduce
I just have a function for scheduling a notification. after that I close my app and wait. but nothing happen. If I don’t close the app or if I put in background(by going to home), the notification will be shown.
scheduleDelayed () {
console.log('scheduleDelayed called : ', Date())
cordova.plugins.notification.local.schedule(
[
{
id: this.countId,
title: 'Scheduled with delay',
text: `${this.countId} -- ${Date()}`,
icon: 'res://balloons',
smallIcon: 'res://balloons',
trigger: { at: new Date(Date.now() + 10000) },
silent: false,
wakeup: true,
foreground: true,
priority: 1
}
],
event => {
console.log('schedule callback')
console.log('this.countId', this.countId)
const notificationId = this.countId
cordova.plugins.notification.local.isScheduled(
notificationId,
result => {
console.log(`${notificationId} schedule result is : ${result}`)
}
)
cordova.plugins.notification.local.hasPermission(function (granted) {
console.log(`hasPermission : ${granted}`)
})
this.countId++
console.log('scheduled')
}
)
}
Context
I am trying to have an app to reminding a person with some sentences.
Debug logs
Include iOS / Android logs
- Android: $ adb logcat ( I am not familiar with that and I don’t know how should I get it, I am using vscode and my mobile phone)
JFYI: I followed all the issues like #1836,#1682,#1483,#899 and I was not successful. @katzer ,@julianlecalvez, @ferryjagers and others, you are all experts I hope you could help me. I am really in the critical situation and I don’t have time to learn android and I can’t 😐
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top GitHub Comments
It’s weird because your code seems ok. Two points you can try, just to see if it works with the app closed : . Use random or unique IDs because reusing the same IDs can be a problem if you never cancel it. . Try with an hardcoded date, or with a delay more important (2 or 3 minutes). Sometimes, my notifications arrives 1 minute late. . I would also try without any variables in the notification text (just in case)
If I still doesn’t work, maybe you can take a look at the battery optimization system which delay notifications in certain case. There’s 2 modes : App Standby and Doze. Both are explained shortly and clearly in the article, but the interesting part is the command lines to force the device entering and leaving each modes : https://developer.android.com/training/monitoring-device-state/doze-standby
Hope it’ll help
Julian
Hi @aefn ! Everything is explained in the article I shared in my previous post. You can easily find a complementary cordova library to manage the battery optimization system. Cheers