I am trying to display messages sent to an android device via FCM.
Just to be clear, I do not want to use the notification property in the fcm message. I prefer the data property to give the mobile developers the ability to customize the notifications.
We currently have the following setup
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
log('Got a message whilst in the Background!');
log('Message data: ${message.data}');
displayNotification();
}
Future<void> _firebaseMessagingForegroundHandler() async {
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
log('Got a message whilst in the foreground!');
log('Message data: ${message.data}');
displayNotification();
});
}
And the following:
Future<void> initFirebase() async {
await Firebase.initializeApp();
initFirebaseComponents();
}
void initFirebaseComponents() {
_firebaseTokenRefreshHandler();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
_firebaseMessagingForegroundHandler();
}
When the Android Device is in the foreground the notifications are perfectly displayed, when the app is minimized the notifications are also perfectly displayed in the background but the moment we kill the app, the notifications are no longer displayed in the background.
I have searched and found no solution, any insight would be really appreciated.