-
-
Notifications
You must be signed in to change notification settings - Fork 2k
cancelLocalNotifications() does not work on Android #2100
Comments
…droid that meant notifications were not being cancelled. Changed matching logic to compare ids only.
Hi @jamesxabregas There is another method on Android which allow remove a scheduled notification only with the id. |
I've tested this on iOS and it is not an issue. The issue only occurs on Android, and as explained it is due to an error in the Android implementation. I have also tested this with other data in the userInfo object but that doesn't make a difference. The other method within the Android implementation is a private method. It is not accessible from the JavaScript interface, it is used internally by the public method of the same name that accepts the userInfo map. Line 794 in 6a81fba
I actually did wonder why cancelLocalNotifications() is implemented the way that it is. It would be far easier to just pass it a string with the id instead of having to parse the JSON object and extract the id. |
I was thinking of: Line 690 in 6a81fba
But I will take a look ASAP. |
I believe clearNotification has a different purpose as it removes a delivered notification from the Notification Center. |
I've also observed a difference in Is it possible that we need to pass |
Fixed in 8.0.0. |
Uh oh!
There was an error while loading. Please reload this page.
I have tested this extensively to see if there was something wrong with the way I was excuting cancelLocalNotification() but it does not appear that this works when providing an id on Android. I am executing it exactly per the documentation.
After adding debug logging into the Anrdoid pacakge I believe I have found the root cause of the issue. In
RNPushNotificationHelper.java
the methodcancelScheduledNotification(ReadableMap userInfo)
tries to extract the id from the provided JSON map and then find the correct notification to cancel.react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java
Lines 783 to 786 in 6a81fba
The problem here is that the
matches
method inRNPushNotificationAttributes.java
is being used incorrectly in this case. That method tries to match every element of the userInfo object with the notification it is iterating on which contains additional info such as the title, message etc. If the user has only provided the id attribute this always returns false.react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationAttributes.java
Lines 200 to 247 in 6a81fba
What is needed in this check is a simple method that matches the id's only.
For instance something like this in
RNPushNotificationHelper.java
:and this in
RNPushNotificationAttributes.java
I am happy to submit a pull request for this issue. I am working on my own fork at the moment.
The text was updated successfully, but these errors were encountered: