这是我当前的实现方式,在打开应用程序时效果很好,但在关闭应用程序时通知未在前台打开。
createNotificationListeners() {
this.notificationListener = firebase.notifications().onNotification((notification) => {
const localNotification = new firebase.notifications.Notification({
sound: 'default',
show_in_foreground: true,
})
.setNotificationId(notification.notificationId)
.setTitle(notification.title)
.setBody(notification.body)
.android.setChannelId('fcm_default_channel')
.android.setSmallIcon('@mipmap/ic_launcher')
.android.setColor('#000000')
.android.setPriority(firebase.notifications.Android.Priority.High);
firebase.notifications().displayNotification(localNotification)
.catch(err => console.error(err));
});
// set channelId
const channel = new firebase.notifications.Android.Channel(
"fcm_default_channel",
"Firebase Alert",
firebase.notifications.Android.Importance.High
);
firebase.notifications().android.createChannel(channel);
}
我已经在github中遇到了这个问题,但没有得到足够的答复