Onesignal-flutter-sdk: NotificationOpenedHandler not called when app is opened from force-quit state

Created on 17 Jan 2020  Â·  8Comments  Â·  Source: OneSignal/OneSignal-Flutter-SDK

Description:

I've been working with opening different routes of my app depending on the notification the app receives. When app is in background/foreground it works perfect. The problem comes when the app is in force-quit or closed. I've been investigating past issues but only one other person pointed out the same problem in the issue #98 on a comment, but that comment got buried and not addressed. I've tried making the runApp run after all Futures are finished, but still not working.

Environment

I'm using Flutter version 1.12.13+hotfix.5 and OneSignal version 2.3.1.

Steps to Reproduce Issue:

  1. I start the app
  2. Background the app
  3. Send a notification and tap on it
  4. NotificationOpenedHandler gets called
  5. I force-quit the app
  6. Send a notification and tap on it
  7. App launches from the ground up but NotificationOpenedHandler is not called.

Anything else:

Help Wanted

Most helpful comment

According to what i know NotificationOpenedHandler is only called when app is opened or in foreground.

I am facing the same issue, already tried with deep links, but it still handled on the Flutter/OneSignal side.

All 8 comments

According to what i know NotificationOpenedHandler is only called when app is opened or in foreground.

I am facing the same issue, already tried with deep links, but it still handled on the Flutter/OneSignal side.

@andrefcferreira Thanks for your reply! I've also thought about deep links but I wondered if what I stated is a bug or expected behaviour...

@andrefcferreira,
That's incorrect. The NotificationOpenedHandlershould be called regardless. It's the onReceived handler that only fires in those conditions.

@jopicornell, please make sure you are setting the opened handler correctly. Can you provide more information regarding your implementation? Perhaps a code snippet? If you are trying to send a background notification, please take a look at our documentation on background notifications for more information. Cheers

From the docs:

OneSignal also supports sending additional data along with a notification as key value pairs. You can read this additional data when a notification is opened by adding a setNotificationOpenedHandler instead.

NOTE: anything using the notification service extension will require writing native code

Closing due to no response

Hi, I'm getting same behavior..

If app is opened or minimized, I can open activity normally.. If app is closed, dont..

Bellow my code (this is called inside method build of main):

OneSignal.shared.init(
  "xxxxxxxxxxxxxx",
  iOSSettings: {
    OSiOSSettings.autoPrompt: false,
    OSiOSSettings.inAppLaunchUrl: true,
  },
);
OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);

OneSignal.shared.setLogLevel(OSLogLevel.verbose, OSLogLevel.none);

bool requiresConsent = await OneSignal.shared.requiresUserPrivacyConsent();
await OneSignal.shared.consentGranted(requiresConsent);

OneSignal.shared.setNotificationReceivedHandler((OSNotification notification) {
  print("PUSH RECEIVED"); -->>>>>> this only works when app is open or in foreground (minimized). If close app (Overview button), doesn't get called
});

OneSignal.shared.setNotificationOpenedHandler((OSNotificationOpenedResult action) async {
      print("PUSH OPENED"); -->>>>>> this only works when app is open or in foreground (minimized). If close app (Overview button), doesn't get called
      await navigatorKey.currentState
          .push(new MaterialPageRoute(builder: (context) => new OfertaPage.fromId(ofertaId)))
          .catchError((onError) {
        print("ERROR");
        print(onError.hashCode);
        print(onError.toString());
      });
    }
});

Environment:
onesignal_flutter: ^2.3.4

$ flutter doctor -v
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Linux, locale pt_BR.UTF-8)
• Flutter version 1.12.13+hotfix.8 at /home/diogo/workspace/flutter
• Framework revision 0b8abb4724 (5 weeks ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /home/diogo/storage/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = /home/diogo/Android/Sdk
• ANDROID_SDK_ROOT = /home/diogo/Android/Sdk/
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.

[✓] Android Studio (version 3.6)
• Android Studio at /opt/android-studio
• Flutter plugin version 44.0.2
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] IntelliJ IDEA Ultimate Edition (version 2019.3)
• IntelliJ at /opt/intellij-idea-ultimate-edition
• Flutter plugin version 44.0.3
• Dart plugin version 193.6494.35

[✓] Connected device (2 available)
• AOSP on IA Emulator • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

how can I start activity if app is closed? Any help is welcome.

Howdy,
You are likely seeing this behavior from sending background notifications. Background notifications can not wake android apps that have been force quit in the app settings. Take a look at our documentation for more info: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-services

Hi, I have one issue for Onesignal push.
When taping the push notification, my app is not being opened.
It took me to open the app for 30s.
so long delayed to open the app by tapping the push notification.

Howdy,
You are likely seeing this behavior from sending background notifications. Background notifications can not wake android apps that have been force quit in the app settings. Take a look at our documentation for more info: https://documentation.onesignal.com/docs/service-extensions#section-notification-extender-services

i use ios,when the app teminated, it can received the notifications,but NotificationOpenedHandler not called

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Allan-Nava picture Allan-Nava  Â·  4Comments

TobiasHeidingsfeld picture TobiasHeidingsfeld  Â·  4Comments

newbieflutter picture newbieflutter  Â·  4Comments

royibernthal picture royibernthal  Â·  3Comments

Bwolfs2 picture Bwolfs2  Â·  5Comments