OneSignal-Flutter-SDK icon indicating copy to clipboard operation
OneSignal-Flutter-SDK copied to clipboard

[Bug]: When the app is closed, notifications that were received while it was open do not open the app

Open AlexFlorenco opened this issue 1 year ago • 5 comments

What happened?

My problem only happens when I receive a notification with the app running (in the foreground or background). When you kill the app and click on the notification, nothing happens. The notification just disappears.

I noticed that the same problem happens with the OneSignal example project here on github. Is this a known limitation?

In all other situations, notifications work perfectly, in the foreground, background and dead.

Steps to reproduce?

class NotificationService {
  NotificationService._();
  static final NotificationService instance = NotificationService._();

  bool initialized = false;
  bool appInBackground = false;
  bool appOpenByNotification = false;

  Future<void> initialize() async {
    OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
    OneSignal.initialize("MY_APP_ID");
    OneSignal.LiveActivities.setupDefault();
    OneSignal.Notifications.clearAll();

    OneSignal.Notifications.addClickListener((event) {
      if (appInBackground) {
        appOpenByNotification = true;
        AdsService.loadAndShowNotificationAd(callback: () {
          handleNotificationReceived(event);
          appOpenByNotification = false;
        });
      } else if (initialized) {
        AdsService.loadAndShowNotificationAd(callback: () {
          handleNotificationReceived(event);
        });
      } else {
        appOpenByNotification = true;
        Timer.periodic(const Duration(milliseconds: 500), (timer) {
          if (initialized) {
            timer.cancel();
            handleNotificationReceived(event);
          }
        });
      }
    });

    OneSignal.Notifications.addForegroundWillDisplayListener((event) {
      event.preventDefault();
      event.notification.display();
    });
  }
}

What did you expect to happen?

I expected the closed app to start when clicking on the notification that was received when the app was running

OneSignal Flutter SDK version

5.2.8

Which platform(s) are affected?

  • [ ] iOS
  • [X] Android

Relevant log output

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

AlexFlorenco avatar Nov 29 '24 13:11 AlexFlorenco

Comigo acontece a mesma coisa... Fico no aguardo de alguma atualização!

ErnestoMoraes avatar Nov 29 '24 16:11 ErnestoMoraes

The same thing is happening to me as well. I noticed this issue about two days ago. I have a Flutter app integrated with OneSignal for long time, and I have never observed this behavior before.

However, in my case, the notification doesn't disappear. Instead, it moves to the end of the notification list. When I click it a second time, it works.

ivnaBat avatar Nov 30 '24 16:11 ivnaBat

However, in my case, the notification doesn't disappear. Instead, it moves to the end of the notification list. When I click it a second time, it works.

It's true, I noticed that on some devices this also happens too

AlexFlorenco avatar Dec 01 '24 20:12 AlexFlorenco

Facing same issue on Tecno Camon 30s and Redmi 12C.

affan3699 avatar Feb 07 '25 15:02 affan3699

same here..... do you have any workaround?

nebis-software avatar Feb 28 '25 17:02 nebis-software

facing the same issue

satyam-dev avatar Apr 08 '25 22:04 satyam-dev

Hi everyone, thank you for reporting this. We believe this is a situation that affects some Samsung and Redmi devices, the fix will be in the next release.

nan-li avatar May 08 '25 15:05 nan-li

This has been fixed in Release 5.3.2. Please test it out and reach out with any further issues or questions.

nan-li avatar May 20 '25 16:05 nan-li