【问题标题】:Flutter: FCM background notification large iconFlutter:FCM后台通知大图标
【发布时间】:2022-07-24 19:47:49
【问题描述】:

我正在使用 firebase_messaging 和 flutter_local_notifications 进行通知,并且我能够在本地(前台)通知的情况下显示一个大图标,但我似乎没有找到一种方法在应用程序时显示相同的大图标是背景。

【问题讨论】:

    标签: flutter push-notification firebase-cloud-messaging


    【解决方案1】:

    使用 largeIcon 的更好方法是在发送通知时在通知负载中使用 image 属性:

    const payload = {
            notification: {
              title: 'title',
              body: 'description',
              image: 'large_icon_url',
              sound : "default"
            },
          };
    

    【讨论】:

      【解决方案2】:

      此代码可帮助您接收通知并在您的应用中使用:

      void initMessaging() {
      var androiInit = AndroidInitializationSettings(‘@mipmap/ic_launcher’);//for logo
        var iosInit = IOSInitializationSettings();
        var initSetting=InitializationSettings(android: androiInit,iOS:
         iosInit);
        fltNotification = FlutterLocalNotificationsPlugin();
        fltNotification.initialize(initSetting);
        var androidDetails =
         AndroidNotificationDetails(‘1’, ‘channelName’, ‘channel 
          Description’);
        var iosDetails = IOSNotificationDetails();
        var generalNotificationDetails =
         NotificationDetails(android: androidDetails, iOS: iosDetails);
      FirebaseMessaging.onMessage.listen((RemoteMessage message) {     RemoteNotification notification=message.notification;
         AndroidNotification android=message.notification?.android;
         if(notification!=null && android!=null){
           fltNotification.show(
             notification.hashCode, notification.title, notification.
             body, generalNotificationDetails);
      }
      });
      }
      

      如果您有任何困难,请查看这篇文章:Flutter Push Notification Medium。 谢谢。

      【讨论】:

      • 抱歉,我的问题是关于大图标的,并不是说我一般无法实现通知。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2012-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多