Flutter android do not get notification when app is killed
1,138
For receiving notification when an app is in background you can use 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;
},
);
Here is the 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'];
} }
Note: I am still finding a solution to receive a solution when the app is in Kill state. I will update answer once get the solution
Comments
-
Paras Dhawan over 1 year
I am using firebase console to send the notification to my android device, it's working fine when the app is in background or foreground state. But it's not receiving the notification in killed state since m not attaching any data it should not be a data notification.
_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'); }, );
-
mcfred almost 3 yearsHi @munish, did you manage to find a solution? I am facing a similar situation.