Closed CrystalAsk closed 3 years ago
Hello @CrystalAsk That method only works with LocalNotifications feature, cancelNotificationsWithId method gets List of IDs as parameter, you can see example usage below.
Push.cancelNotificationsWithId([1001,1002,1003]);
Thank you for your interest 👍
Hi @aktug
Means that currently I cannot cancelled specific notification ID that registered in notification manager?
You can cancel any notification that registered in the notification manager if you know ID of notification 👍
If i created a notification ID (001), as logically when i cancelled the notification ID (001), it able to be cancelled, right? Below is my sample code
Map<String, dynamic> localNotification = { HMSLocalNotificationAttr.ID: "001", HMSLocalNotificationAttr.TITLE: 'Notification Title', HMSLocalNotificationAttr.MESSAGE: 'Notification Message', HMSLocalNotificationAttr.TICKER: "OptionalTicker", HMSLocalNotificationAttr.TAG: "push-tag", HMSLocalNotificationAttr.BIG_TEXT: 'This is a bigText', HMSLocalNotificationAttr.SUB_TEXT: 'This is a subText', HMSLocalNotificationAttr.LARGE_ICON: 'ic_launcher', HMSLocalNotificationAttr.SMALL_ICON: 'ic_notification', HMSLocalNotificationAttr.COLOR: "white", HMSLocalNotificationAttr.VIBRATE: true, HMSLocalNotificationAttr.VIBRATE_DURATION: 1000.0, HMSLocalNotificationAttr.ONGOING: false, HMSLocalNotificationAttr.DONT_NOTIFY_IN_FOREGROUND: false, HMSLocalNotificationAttr.AUTO_CANCEL: false, HMSLocalNotificationAttr.INVOKE_APP: false, HMSLocalNotificationAttr.ACTIONS: ["Yes", "No"], HMSLocalNotificationAttr.REPEAT_TYPE: RepeatType.MINUTE, HMSLocalNotificationAttr.FIRE_DATE: DateTime.now().add(Duration(minutes: 1)).millisecondsSinceEpoch, }; Map<String, dynamic> response = await Push.localNotificationSchedule(localNotification);
//cancel ID 001 Push.cancelNotificationsWithId([001]);
Sorry, may be there is misunderstanding for my issue, actually I want to cancel the pending scheduled notification with a list of specific ID.
My scenario is: Firstly I create 2 types of notification (known as A and B) which notification A sending notification every 2 hours, while notification B sending notification every 3 hours. When the user disabled the notification B, my apps should cancel notification B (which stops sending notification B every 3 hours) and only send notification A every 2 hours.
On Tue, Dec 29, 2020 at 6:44 PM Aktug Urun notifications@github.com wrote:
You can get notification's Infos with Push.getNotifications() method. And its response is : [image: image] https://user-images.githubusercontent.com/20382405/103277648-97002780-49da-11eb-88e8-8342cca0cf8d.png
As you can see, HMSLocalNotificationAttr.ID and statusBarNotificationId are different, you can cancel any notification with statusBarNotificationId 👍
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/HMS-Core/hms-flutter-plugin/issues/55#issuecomment-752031321, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASFNH6OUN6HEL36JABNNDSTSXGXHNANCNFSM4VDZXE7A .
Hello @CrystalAsk , it seems that Push.cancelNotificationsWithId([001,002]);
method can only remove the notifications that are already posted or in other words: displayed on the UI, but since the scheduled notifications are still pending and not posted yet to the notification manager, they can't be cancelled via this method.
For the time being, you can use the Push.cancelScheduledNotifications();
method to cancel all scheduled notifications and then you can register the ones needed again . On the next release we can provide a way to also cancel scheduled notifications by specifying an ID. Thank you for pointing out this use case.
Ok, noted. Thanks 👍
Hi,
May I know is there anyway to cancel certain notification ID that registered in notification manager instead of cancelled all? I tried with this function "Push.cancelNotificationsWithId" it seem like not work.