FCM:当应用在后台运行时,无法收到弹出通知

时间:2020-07-21 02:42:42

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

我正在使用“ Firebase Cloud Messaging”接收通知,并使用“ flutter_local_notifications”插件在我的设备上进行配置和显示。所以我当前的情况是当我的应用程序运行(在前台)时,我将按预期收到适当的通知(弹出窗口加上它存储在系统托盘中),如下所示:

enter image description here

它也会按预期方式存储在系统托盘中。

但是当我将应用程序保留在后台并发布通知请求时......它只是将通知存储在任务栏中,但没有显示弹出通知。像这样:

enter image description here

如上图所示....它仅将通知存储在图像托盘中,而不像应用程序在前台运行时那样显示弹出通知。

我以为我是“ backgroundMessage”回调中的一个问题,但是观察到的是,每当我在应用程序处于后台时发布通知时,它总是执行此异常,而不是执行“ backgroundMessage”回调:

W/FirebaseMessaging(22744): Missing Default Notification Channel metadata in AndroidManifest. Default value will be used.

以下是我配置FirebaseMessaging实例的代码

 _firebaseMessaging.configure(
      onMessage: notification,
      onBackgroundMessage: notificationBack,
    );

“通知”回调

Future<dynamic> notification(Map<String,dynamic> message) async {

   AndroidNotificationDetails androidNotificationDetails =
    AndroidNotificationDetails(
        'Channel ID', 'Channel title', 'channel body',
        priority: Priority.High,
        importance: Importance.Max,
        ticker: 'test');

    IOSNotificationDetails iosNotificationDetails = IOSNotificationDetails();

    NotificationDetails notificationDetails =
    NotificationDetails(androidNotificationDetails, iosNotificationDetails);
    await _flutterLocalNotificationsPlugin.show(
        0, 'Notification', 'New Notification', notificationDetails);
  }

“ notificationBack”回调

static Future<dynamic> notificationBack(Map<String,dynamic> message) async {

    AndroidNotificationDetails androidNotificationDetails =
    AndroidNotificationDetails(
        'Channel ID', 'Channel title', 'channel body',
        priority: Priority.High,
        importance: Importance.Max,
        visibility: NotificationVisibility.Public,
        ticker: 'test');

    IOSNotificationDetails iosNotificationDetails = IOSNotificationDetails();

    NotificationDetails notificationDetails =
    NotificationDetails(androidNotificationDetails, iosNotificationDetails);
    await _flutterLocalNotificationsPluginBack.show(
        0, 'Hello there', 'please subscribe my channel', notificationDetails);
  }

AndroidManifest.xml

enter image description here enter image description here

很抱歉,屏幕截图而不是文本格式....但我不知道为什么所有这些术语都以红色突出显示“无法解析符号....”和“未解析的包'flutterlocalnotifications'”(如果收到) flutterlocalnotification。

我的主要目标是即使应用程序处于后台,也要获得游戏弹出通知和系统托盘中的一条通知。 (就像它在前景中时的显示方式一样。)

我知道这个问题有点长,但是我必须提供有关该问题的所有观察结果,所以请尽量不要提出来:)

在此先感谢您的帮助。

0 个答案:

没有答案