awesome_notifications icon indicating copy to clipboard operation
awesome_notifications copied to clipboard

Notification fires itself over and over again

Open talhakerpicci opened this issue 3 years ago • 27 comments

Hey there!

So i have been dealing with this problem and couldnt really find any sollution. Im trying to implement a feature where user will be able to set notifications on certain days, time and minutes. An example as follows: On mondays, hour: 11, minute: 30, repeat always. And user will get notification every monday, at 11.30 oclock.

So let me show my code:

This is how i initialize it

  AwesomeNotifications().initialize(
    'resource://drawable/icon',
    [
      NotificationChannel(
        channelKey: 'scheduled',
        channelName: 'Scheduled notifications',
        channelDescription: 'Scheduled notification channel',
        ledColor: Colors.white,
      ),
    ],
  );

And the following code is how i create scheduled notification:

        reminder.days.forEach((int day) async {
          await AwesomeNotifications().createNotification(
            content: NotificationContent(
              id: (reminder.id + '$day').hashCode,
              channelKey: 'scheduled',
              title: 'Reading Reminder',
              body: reminder.customMessage != '' ? reminder.customMessage : 'Reading reminder for ${bookData.title}',
            ),
            schedule: NotificationCalendar(
              repeats: true,
              weekday: day,
              hour: int.parse(reminder.timeOfDay.split(':')[0]), // 18
              minute: int.parse(reminder.timeOfDay.split(':')[1]), // 30
              timeZone: localTimeZone,
            ),
          );
        });

reminder.days is basicly a list of integers from 1 to 7, represents week days.

So as i said i want to show notification to user say every Sunday at 17.30 lets say. Thats the code i use and its working but the problem is once it shows a notification it never stops and constantly repeats itself again untill i cancel it. Like every second it pops a new notification and never stops.

I found a thread where one user had the same problem: https://github.com/rafaelsetragni/awesome_notifications/issues/180

So i have the same problem and cant solve it.

Platform: Android (tested on multiple real devices) awesome_notifications version: ^0.0.6+9 localTimeZone: Europe/Istanbul

Any help? Thanks in advance

Edit: just realized one more issue opened already https://github.com/rafaelsetragni/awesome_notifications/issues/211 Looking forward to hear for updates. Would like to contribute if i can

talhakerpicci avatar Jul 02 '21 15:07 talhakerpicci

problem is once it shows a notification it never stops and constantly repeats itself again untill i cancel it. Like every second it pops a new notification and never stops.

You can use one thing. But this will not cancel the notification, which means user will not get constant notification, the notification will not trouble the user, else when user removes the notification before a minute then it will not be removed after a minute it will be removed or cancelled but it will surely be better,

Use onlyAlertOnce: true in the notification initialisation• It will not constantly alert the use but once, but if you try to remove the notification before a minute it will again pop down, but it will go if the user will not touch it.

Still better but worse.

madd-project avatar Jul 03 '21 04:07 madd-project

Screenshot 2021-07-03 at 09-53-24 madd-project toodolee

like this @N1ght-Fury

madd-project avatar Jul 03 '21 04:07 madd-project

but still, Rafaelsetragni must check this, he said in my issue #211 he wants to take a meet, but yeah, I guess he never read my comment there. I hope this is not helpful, but this is the best currently.

madd-project avatar Jul 03 '21 04:07 madd-project

@madd-project Oh i see. Thank you for that. Yea as you said thats a workaround but author of the package should really have a look at this. This is a very critical bug imo and should be fixed immediately.

I will try to downgrade the package and see if the same problem occurs on older versions. I will post the result here

talhakerpicci avatar Jul 03 '21 06:07 talhakerpicci

So i tested some old version and same problem occurs on them as well. Looking for updates at this point

talhakerpicci avatar Jul 03 '21 07:07 talhakerpicci

Inviting @rafaelsetragni ...

madd-project avatar Jul 03 '21 07:07 madd-project

Try to check if this fix works for you:

Add this into your pusbpec.yaml:

# awesome_notifications: ^0.0.6+9
awesome_notifications:
     git:
       url: https://github.com/rafaelsetragni/awesome_notifications.git
       ref: 85b7b34

and add after description the tag bellow to enable git references into pusbec.yaml:

description: lalalalalalala
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

This git link is a direct reference to the branch fix-looped-notifications

Also, try to add the second condition to zero, to avoid that every new second inside the valid minute turns into an valid condition.

OBS:

For now some future improvements will be delayed a bit because of this little guy:

But i will try as soon as possible to answer you guys and send new fixes. I believe this loop happens because the notification is getting scheduled to the same date as now, and for every past second the condition is still true. So i change the next valid date method to only consider valid schedules to 1 second in future and beyond.

Remembering that everyone can debug the native code using Android Studio and send me your own fixes. Every helps is welcome.

rafaelsetragni avatar Jul 05 '21 02:07 rafaelsetragni

Hey! Thank you so much for your efforts really appreciate it.

The new branch you provided worked for me after setting second:0. It works without any problems now. Thank you.

Here is the code that i use right now:

await AwesomeNotifications().createNotification(
            content: NotificationContent(
              id: (reminder.id + '$day').hashCode,
              channelKey: 'scheduled',
              title: 'Reading Reminder',
              body: reminder.customMessage != '' ? reminder.customMessage : 'Reading reminder for ${bookData.title}',
            ),
            schedule: NotificationCalendar(
              repeats: true,
              weekday: day,
              hour: int.parse(reminder.timeOfDay.split(':')[0]),
              minute: int.parse(reminder.timeOfDay.split(':')[1]),
              second: 0,
              timeZone: localTimeZone,
            ),
          );

Also congrats with the baby :) Best wishes ❤️

talhakerpicci avatar Jul 05 '21 09:07 talhakerpicci

By the way, i tested it again without the specific branch you provided, and after adding second:0 parameter it also works without any problems. So anyone having this problem can just add that parameter and it will work on any version i guess.

Thanks again, closing the issue

talhakerpicci avatar Jul 05 '21 12:07 talhakerpicci

Well maybe it was a little too early to close the issue :(

So i have tried it with other devices and sadly, the same problem still occurs even after i did everything i said in the previous comments. It does not even stop after 1 minute passes, its like an endless loop, constantly showing notification.

And here is what i found, im from Turkey and my device language is Turkish. When i changed device language to English, it stopped showing notifications endlessly. At this point i am pretty sure device language is causing bugs if its not set to English.

How does device language and showing notifications related? @rafaelsetragni Sir I know you are busy but this seems like a minor bug about the device language. As far as i can see thats what causes the problem. Could you please have a look at it one last time?

talhakerpicci avatar Jul 05 '21 17:07 talhakerpicci

So when i create a new schedule, here is what i see on my debug console:

25 D/NotificationScheduler(26120): Scheduled created

But it shows it over and over again and it fires a new notification endlessly.

When i change the device language to English, the problem stops. I tried to debug the code but i coudlnt solve it :(

Here is a github repo if you want to test it: https://github.com/N1ght-Fury/notification-error. Set device language to Turkish first and run the application. And then turn it back to English and you will see it runs without any problems.

talhakerpicci avatar Jul 06 '21 09:07 talhakerpicci

Here is a video i just take to make it more clear. Please watch: https://www.youtube.com/watch?v=mvz4QJv-VDA

Edit: make sure you delet the application after setting the new language. and then run again

talhakerpicci avatar Jul 06 '21 10:07 talhakerpicci

hey guys... im also having the same problem. when i set the device language to turkish it keeps showing notifications nonstop :( after i set it back to english it just works flawlessly. any help to solve this please?

Mohi-exe avatar Jul 06 '21 10:07 Mohi-exe

I couldnt reproduce this error. For me, even changing the main language to turkish, the schedules are being correctly created. If someone could attach a native debug into the app using Android Studio to discover whats going on, will help me a lot.

rafaelsetragni avatar Jul 07 '21 23:07 rafaelsetragni

@rafaelsetragni i ran the project on android studio. could you please tell how can i get native debug? or you need some kind of log data? like you want me to copy and paste logcat here?

talhakerpicci avatar Jul 08 '21 06:07 talhakerpicci

Can you also try again this way: set timeZone: "Europe/Istanbul" and also set device language to Turkish. Maybe you can reproduce the error this way.

talhakerpicci avatar Jul 08 '21 13:07 talhakerpicci

@rafaelsetragni Love you, Congrats, for the @rafaelsetragni Jr. Junior is so cute. Love you. Love You , And You are so Lucky. ❤️ It is like Harward Stark and the Tony... That Endgame Movie Scene,

madd-project avatar Jul 09 '21 04:07 madd-project

Well the Answer was not working.. Stillll

madd-project avatar Jul 15 '21 06:07 madd-project

Same for me. It actually works for me when i set the second: 0. It only doesnt work on Turkish devices. I guess it happens because of timeZone. It creates the cron job wrong and fires notification every second. Thats what i think is happening.

talhakerpicci avatar Jul 16 '21 19:07 talhakerpicci

The problem is that I can not simulate an Turkish device. Im planning to create a YouTube video showing how to debug native and flutter level.

That way everyone will be capable to debug and realize what's going on, with every flutter app and every plugin.

rafaelsetragni avatar Jul 17 '21 02:07 rafaelsetragni

The problem is that I can not simulate an Turkish device. Im planning to create a YouTube video showing how to debug native and flutter level.

That way everyone will be capable to debug and realize what's going on, with every flutter app and every plugin.

Looking forward to it!

talhakerpicci avatar Jul 17 '21 09:07 talhakerpicci

I am also having this issue. @talhakerpicci @talhakerpicci @madd-project @Mohi-exe @rafaelsetragni Is there any progress?

What information can I provide to debug this?

rokk4 avatar May 13 '22 07:05 rokk4

@rokk4 move to beta 3 and try again, setting the seconds to 0.

rafaelsetragni avatar May 13 '22 10:05 rafaelsetragni

Beta 5 still has the issue

mrRedSun avatar Jul 13 '22 10:07 mrRedSun

Anytime repeats is set will lead to notifications either being spammed like crazy or just every time notification is dismissed. Android only, API 27 Setting onlyAlertOnce: true doesn't help

mrRedSun avatar Jul 13 '22 10:07 mrRedSun

Try to set the second parameter to 0

rafaelsetragni avatar Jul 15 '22 13:07 rafaelsetragni

Try to set the second parameter to 0

This works. I had the same issue and fixed with this solution before finding this ticket.

qasim90 avatar Jul 28 '22 12:07 qasim90

Hi! Sorry for taking so long to respond to your issue on GitHub. I was focused on releasing the new 0.7.0 version of awesome_notifications and awesome_notifications_fcm and i didn't had time enough to do both. But now I can answer all your questions.

So now i'm asking you to recreate this topic using the new issue template. There's a lot of missing informations that i need to understand your problem, and all the instructions are already in the new issue template. Also, remember to check beforehand if your issue was posted by another user.

So I will automatically close all previous issues so far. Sorry for the inconvenience and i will be waiting for your new issue request.

Thank you so much for your support!

rafaelsetragni avatar Sep 29 '22 17:09 rafaelsetragni