【问题标题】:Flutter Show Notification when app is open with Firebase Messaging使用 Firebase 消息打开应用时 Flutter 显示通知
【发布时间】:2020-08-06 14:18:42
【问题描述】:

应用程序接收我在后台或关闭模式下发送的所有通知,但我还想在用户玩应用程序时打开应用程序时显示通知。

      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message");
        FlutterRingtonePlayer.playNotification();
      },
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");

      },
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
        // TODO optional
      },

【问题讨论】:

    标签: firebase flutter firebase-cloud-messaging


    【解决方案1】:

    如果您想在系统托盘中显示通知,就像应用在后台时一样,您可以使用包flutter_local_notifications

    这样,当您通过onMessage 收到通知时,您可以使用以下内容:

    AndroidNotificationDetails notificationAndroidSpecifics =
        AndroidNotificationDetails(
            groupChannelId, groupChannelName, groupChannelDescription,
            importance: Importance.Max,
            priority: Priority.High,
            groupKey: groupKey);
    
    NotificationDetails notificationPlatformSpecifics =
        NotificationDetails(notificationAndroidSpecifics, null);
    
    await flutterLocalNotificationsPlugin.show(
        1,
        'Jeff Chang',
        'Please join us to celebrate the...',
        notificationPlatformSpecifics);
    

    查看他们的文档以获取更多示例!

    【讨论】:

      猜你喜欢
      • 2020-12-31
      • 1970-01-01
      • 2020-08-25
      • 2020-11-25
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多