question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The notifications will not trigger when app is closed(killed) and will be triggered after opening the app

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
julianlecalvezcommented, Apr 20, 2020

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

1reaction
julianlecalvezcommented, Apr 23, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Background fetch after app is force-quit - Apple Developer
Currently my app works performs background fetches correctly when it has been backgrounded, but after force-quitting the app it stops fetching. Specifically I ......
Read more >
Notifications - Expo Documentation
Notifications. The expo-notifications provides an API to fetch push notification tokens and to present, schedule, receive and respond to notifications.
Read more >
Service | Android Developers
startService() do not nest (though they do result in multiple corresponding calls to onStartCommand()), so no matter how many times it is started...
Read more >
Notifications Not Shown - Mobile Push
"Delivered" notifications in OneSignal means we have successfully sent the notification to the push servers (FCM/APNS/WNS etc..). These push servers then ...
Read more >
Receive messages in a Flutter app - Firebase - Google
On iOS, if the user swipes away the application from the app switcher, it must be manually reopened for background messages to start...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found