bhandaribhumin / cordova-plugin-local-notification-12

Apache License 2.0
17 stars 35 forks source link

Resolve the issue preventing the '.cancel()' method from canceling scheduled pending intents in Android Alarm Manager. #13

Closed marco-hd closed 7 months ago

marco-hd commented 9 months ago

I observed that in Android 12/13, when utilizing the .cancel() method, it fails to cancel the event within the alarm manager. As a result, the pending event persists and will be broadcasted as initially scheduled. Consequently, during broadcasting, if it coincides with another scheduled notification item (with the same id), it gets captured and gives the impression of triggering earlier than intended. However, in reality, this pertains to the old notification which hasn't been effectively cleared from the alarm manager.

How to reproduce:

Therefore, the solution is to depend on the requestCode of the PendingIntent.getBroadcast which is assigned to each scheduled item so the pending intent can be correctly found.

P.S. related also to https://github.com/katzer/cordova-plugin-local-notifications/issues/1701 (SamsungAlarmManager: !@too many alarms (500) registered from uid)