I am using:
flutter version 2.2
firebase_messaging: ^10.0.2
I receive push notification, then click on it and the app is opened.
Then I do not see FirebaseMessaging.onMessageOpenedApp.listen getting called (the callback is sending debug email to me, but I don't receive any)
My questions are
(optional) How can I debug android app with android studio debugur simulating case above, so app is killed not opened, then is opened via notification
What can be the issue here ? Why that stream is not triggered ? I initialise it in main.dart
PS: All other methods work fine, so if app is on foreground, onMessage.listen works great. I need to handle onMessageOpenedApp so I can redirect user to proper view based on notification information
For the first question:
To view the logs from your app, you can use the 'Logcat' tab in Android Studio or IntelliJ:

For the second question:
If your app is terminated and you want to receive a notification click callback, you should use:
FirebaseMessaging.instance.getInitialMessage().then((message) {
if (message != null) {
// DO YOUR THING HERE
}
});
, because according to the Flutter team's comments for onMessageopenedApp function:
/// If your app is opened via a notification whilst the app is terminated,
/// see [getInitialMessage].
I've been in this issue for a while and just noticed that, there are 3 workarounds provided by firebase_messaging plugin.
You can find details below:
onMessage callback will be called which is actually a Stream<RemoteMessage> and there will be no notification in notification tray. so you can handle it likeFirebaseMessaging.onMessage.listen((message) {
// handle accordingly
});
onMessageOpenedApp callback will be called which is also a Stream<RemoteMessage> so you can handle it likeFirebaseMessaging.onMessageOpenedApp.listen((message) {
// handle accordingly
});
Stream<RemoteMessage> cannot be triggered. So in that case firebase_messaging provides you getInitialMessage callback which is actually a Future<RemoteMessage?>. you can use it like:FirebaseMessaging.instance.getInitialMessage().then((message) {
if (message != null) {
// handle accordingly
}
});
Note that getInitializeMessage callback will be triggered every time user opens the app if its handled in main.dart file. so maybe message is null, to prevent null pointer exception I put if(message != null) condition here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With