react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

Android: Remove notifications from 'notification center'

Open jonesn3 opened this issue 9 years ago • 9 comments

According to the documentation 'cancelLocalNotifications' is supposed to remove notifications from the 'notification center' in additiion to remove scheduled notifications by id. However, the dismissing of notifications does not seem to workinging on Android.

jonesn3 avatar Jan 18 '17 09:01 jonesn3

@varungupta85 we had this working a while back didn't we?

npomfret avatar Jan 31 '17 11:01 npomfret

@npomfret I have been using my own fork for the repo for some time as I have been having some problems with some of the commits and I didn't really need those features. But to answer your question, yes this has been working in the past and still works on my fork and I don't think that part of the code has changed, so it should be working now. There may be some problems with the way the API is invoked by @JonesN7 . @JonesN7, please keep in mind that you need to provide an object of shape {id: <notificationId>} to cancel a local notification by id and it will only cancel that notification. If you want to cancel all notifications, then you can use cancelAllLocalNotifications API. Please share your code if you are still having problems.

varungupta85 avatar Jan 31 '17 12:01 varungupta85

Just to make sure we are on the same page; I am able to cancel scheduled local notifications by their ID, using cancalLocalNotifications. What this does not do for me, is remove a delivered notification from the status bar. So I can cancel future notification, but not remove delivered ones from the status bar, which from what I understand is the same as the 'notification centre' on iOS, but maybe I am misusing that term.

jonesn3 avatar Jan 31 '17 16:01 jonesn3

@JonesN7 This is the line of code that should be called when a specific notification is canceled.

https://github.com/zo0r/react-native-push-notification/blob/master/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java#L424

cancelScheduledNotification is the method that should be called. I have a feeling that may be the notification is not canceled as well or you have more than one notification with different ids but same text. So, the other ones won't go away from the notification center. Can you confirm that you are seeing the log messages present in the cancelScheduledNotification method?

varungupta85 avatar Feb 03 '17 03:02 varungupta85

I am trying to cancel two notifications. One that that has been delivered, and one scheduled but not delivered. The future one is correctly canceled, and this is shown the the log of the cancelScheduledNotification method. The one that has been delivered, and has an icon in the statusbar, does not show up in the log.

jonesn3 avatar Feb 03 '17 14:02 jonesn3

The two notifications would have different ids unless they are repeating notifications. So, you will need to cancel both the notifications separately.

Sent from my iPhone

On 03-Feb-2017, at 8:24 PM, Espen Jones [email protected] wrote:

I am trying to cancel two notifications. One that that has been delivered, and one scheduled but not delivered. The future one is correctly canceled, and this is shown the the log of the cancelScheduledNotification method. The one that has been delivered, and has an icon in the statusbar, does not show up in the log.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

varungupta85 avatar Feb 03 '17 15:02 varungupta85

Hello.

For someone still facing this issue you can use the method clearLocalNotification(id). I've used the id as an integer, but you may try with string too, idk if it works.

I've tried it on Android and it's working (removing an already delivered notification). Hope it works.

juanfer0002 avatar Nov 16 '18 16:11 juanfer0002

Just leaving this here, https://stackoverflow.com/a/20007350/5844171 On the project, cancelLocalNotification calls this

NotificationManager notificationManager = notificationManager();
notificationManager.cancel(notificationID);

So if when you're generating your notification you have a tag property it's never being passed and thus not cleared

SergioReis97 avatar May 13 '19 10:05 SergioReis97

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar May 29 '20 00:05 github-actions[bot]