(Android) Capacitor Local Notifications Issues. Scheduled Notifications are not delivered if the app has been closed for more than 2 hours

I’m having issues with Local Notifications on Android. (All Android devices, and all versions of android). I’ve scheduled multiple notifications to trigger several times throughout the day, but the notifications are only delivered for a period of 2 hours after the app is closed. After the 2 hours have passed, the notifications are not delivered anymore. Notifications will always fire immediately after enter the app, or (which is even stranger) they will fire immediately after I plug in the charger. This is happening only on android, it never happened on iOS. Before closing the app, I always verify the pending notifications array and all notifications are there. And with every notification I’m scheduling, I am setting allowWhileIdle: true.

I’ve followed all the documentation here: Local Notifications Capacitor Plugin API | Capacitor Documentation

This is all on Capacitor 4 (Android SDK 32), and the plugin version is 4.1.4. I even tried with with Capacitor 5 and plugin 5.0.0.

Any help would be appreciated with this. Thanks!

PS: The app is for scheduling tasks and sometimes I can have up to 4 notifications in an hour, rarely I schedule two notifications at the same time.

Look to be a phone OS related thing. If they are fired when the charger is plugged, that means the phone manufacturer is high jacking the phone battery management so that the phone can last when on battery. Huawei are notorious of doing thing like this on their phone.

Maybe try running your phone on Performance mode if it has one, AI battery conserving related software and Power Saving mode of any sort (they call it different names depending on the phone manufacturer), that just means the phone will run as Android was intended to do so. It means nothing aside from that when it comes to performance (most of the time, I don’t know about gaming phones, never had one)

I will try to do so, the problem is the phone I’ve been testing on is a Samsung S20 and it never had the ‘save battery mode’ turned on

Me neither lol.

Huawei View 10 did some weird things in their phone management sofware that basically killed most background functionality, and for app like Microsoft ToDo made them unusable. Later I found about the performance mode and that let the phone run closely to how my previous Android ran, so I just assumed that was closer to stock Android management.

I know Oneplus do something similar to their phone management, so it wouldn’t be weird for Samsung to do the same, in my opinion. I don’t have a Samsung phone, so sadly I can’t test what I think may be happening.

Btw, I have used Local notifications on Oneplus, and it works as expected, I didn’t have to do anything. It could be something specific to the phone, or maybe something else. Sorry I can’t help you further.

Local Notifications has a ‘allowWhileIdle’ option that may help. It prevents Doze from restricting the notification. Local Notifications Capacitor Plugin API | Capacitor Documentation