Android 当应用程序处于后台时,无法从推送通知中获取标题和消息

Android 当应用程序处于后台时,无法从推送通知中获取标题和消息,android,firebase,react-native,firebase-cloud-messaging,react-native-firebase,Android,Firebase,React Native,Firebase Cloud Messaging,React Native Firebase,我正在尝试构建react本机应用程序,它使用react本机推送通知实现推送通知。现在,当应用程序处于“前台”时,我可以处理notification.title和notification.message,并在应用程序中的警报中显示(通过PushNotification.configure的onNotification)。当应用程序处于“后台”时,我能够收到通知,当我单击它时,应用程序被打开或出现在前台。在这里,我想获取相同的notification.title和notification.messa

我正在尝试构建react本机应用程序,它使用react本机推送通知实现推送通知。现在,当应用程序处于“前台”时,我可以处理notification.title和notification.message,并在应用程序中的警报中显示(通过PushNotification.configure的onNotification)。当应用程序处于“后台”时,我能够收到通知,当我单击它时,应用程序被打开或出现在前台。在这里,我想获取相同的notification.title和notification.message来显示,但在notification JSON中看不到这些字段(notification.data也是空的)。以下是PushNotification中的代码。配置的onNotification:

    onNotification: function (notification) {
        console.log('NOTIFICATION:', JSON.stringify(notification));
        if (notification.foreground) {
          if(notification.userInteraction) {
            Alert.alert("Title:" + notification.title + " Message:" + notification.message);
          } else {
            PushNotification.localNotification({
              id: notification.id,
              autoCancel: true,
              title: notification.title,
              message: notification.message,
              vibrate: true,
              vibration: 300,
              playSound: true,
              soundName: 'default',
            });
            PushNotification.cancelLocalNotifications({id: notification.id});
          }
        } else {
          console.log("notification.data:", JSON.stringify(notification.data));
          if(notification.userInteraction) {
            console.log("Showing modal with notification details...");
          }
        }
      },

感谢您抽出时间来研究此问题。

当通知来自后台时,您可以看到其他道具,如数据?只有标题和消息不可用?因为在后台,您可能处于退出状态,所以只有在安装了组件时才需要调用onNotification()。如果调用得太早(例如,在类构造函数或全局范围内),通知数据可能不可用。下面是我根据应用程序的位置接收到的JSON:背景:{“前台”:false,“google.delivered_priority”:“normal”,“google.sent_time”:1602792622279,“google.ttl”:2419200,“google.original_priority”:“normal”,“from”:“736…”,“google.message_id”:“0:160…”,“collapse_key”:“com.abc”,“data”:{}}前台:{“前台”:true,“用户交互”:false,“id”:“-899701097”,“data”:{},“颜色”:null,“声音”:null,“标题”:“测试标题”,“消息”:“测试消息”}我也在寻找后台应用程序的标题和消息。