简体   繁体   中英

FCM FirebaseMessaging.onMessageOpenedApp Won't work

Although all the other functions work perfectly, I receive the message and display it in all conditions, in the background, foreground or initial message.

in the background:

Future<void> backgroundHandler(RemoteMessage message) async {
  print(message.data.toString());
  print(message.notification!.title);
}

FirebaseMessaging.onBackgroundMessage(backgroundHandler);

in the foreground:

FirebaseMessaging.onMessage.listen((message) {
      if (message.notification != null) {
        add(NotificationRecieved(message));
      }
    });

in the initialization of the application:

await FirebaseMessaging.instance.getInitialMessage().then((message) {
      if (message != null) {
        LocalNotificationService.display(message);
        return message.data["route"];
      }
    });

but this doesn't work: when I click on the notification

FirebaseMessaging.onMessageOpenedApp.listen(
      (message) {
        toast(message.data.toString());
        var route = message.data["route"];
        Navigator.pushNamed(context, route);
      },
    );

the function (onMessageOpenedApp.listen) itself isn't being called.

Do Checking Like This:


    FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
     
      RemoteNotification? notification = message.notification;
      AndroidNotification? android = message.notification!.android;
   
      if (notification != null && android != null) {


-----do your action here



}

Try this:

FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage? message) {
      if (message != null && message.data["route"] != null) {
        toast(message.data.toString());
        var route = message.data["route"];
        Navigator.pushNamed(context, route);
      }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM