我正在使用Firebase控制台将通知发送到我的android设备,当应用程序处于后台或前台状态时,它工作正常。但是它没有收到处于终止状态的通知,因为m不附加任何数据,因此不应该是数据通知。
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
MessageDialog messageDialog = new MessageDialog();
messageDialog.information(context, "Notification");
print('on message $message');
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
答案 0 :(得分:1)
要在后台运行应用程序时接收通知,可以使用 onBackgroundMessage
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
print('on message $message');
handleNotification(message);
return;
},
onBackgroundMessage: fcmBackgroundMessageHandler,
onResume: (Map<String, dynamic> message) {
print('$fcmTag on resume $message');
return;
},
onLaunch: (Map<String, dynamic> message) {
print('$fcmTag on launch $message');
return;
},
);
这是 fcmBackgroundMessageHandler
static Future<dynamic> fcmBackgroundMessageHandler(Map<String, dynamic> message) {
if (message.containsKey('data')) {
// Handle data message
final dynamic data = message['data'];
//handleNotification(message);
}
if (message.containsKey('notification')) {
// Handle notification message
final dynamic notification = message['notification'];
} }
注意:我仍在寻找解决方案,以便在应用程序处于Kill状态时收到解决方案。得到解决方案后,我将更新答案