I am trying to build a cross platform app (only works on android for now) with Flutter, that notifies the user when a operation is ongoing (for volunteer firefighters) and they can send feedback if they will be participating. I did that with a FCM Notification and data payload. Now i am trying to implement a function, that will not show a notification and tell the server, that they do not have time. I am using flutter_local_notifications for the notification. When i am in the app or have the app minimzed, it works perfectly. But when "kill" the app when swiping up in the app drawer, I no longer get a notification.
I was expecting it to show, as it is a data only message (no notification field provided). The function should be implemented clientside, so it should not send a request to the server to stop sending the notifications. Is there any way to either run a seperate piece of code in the FirebaseMessaging.onBackgroundNotification(function) or is it possible to prevent the user from killing the app? Is there a background service I can maybe implement? I searched hours but with no result. I hope there is a solution, that works on both platforms (iOS, Android)
2
Answers
i have found out i am a dumbass. I solved it by disabling battery opimisation and by adding the POST_NOTIFICATIONS permission to my manifest. I am sorry if I have wasted anyones time, i must have read over it in the docs.
You can handle background messages when app is terminated via the
onBackgroundMessage
handler. Data only messages are considered low priority by devices when your application is in the background or terminated, and will be ignored. You can however explicitly increase the priority by sending additional properties on the FCM payload.https://firebase.flutter.dev/docs/messaging/usage