首页 > 解决方案 > 前台推送通知

问题描述

每当我使用来自 firebase 的云消息发送通知时,推送通知都会强制应用程序进入另一个屏幕,甚至无需用户点击通知。

我希望用户首先点击通知,然后将其推送到另一个屏幕。下面的代码适用于在前台运行的应用程序,我遇到了这个问题。

提前泰。适用于安卓*

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      final routeFromMessage = message.data['route'];
      Navigator.of(context).pushNamed(routeFromMessage);

      RemoteNotification? notification = message.notification;
      AndroidNotification? android = message.notification?.android;
      if (notification != null && android != null && !kIsWeb) {
        flutterLocalNotificationsPlugin!.show(
          notification.hashCode,
          notification.title,
          notification.body,
          NotificationDetails(
            android: AndroidNotificationDetails(
              channel!.id,
              channel!.name,
              channel!.description,
              //      one that already exists in example app.
              icon: 'launch_background',
            ),
          ),
          payload: message.data['route'],
        );
      }
    }); 

标签: firebaseflutterandroid-studiofirebase-cloud-messaging

解决方案


推荐阅读