[Flutter] Notifications not showing on Android when app is in background (even with Firebase configured)

SebastienC9 days ago

Hi,

I'm working on a custom version of the Traccar Manager Flutter app from the official repo: https://github.com/traccar/traccar-manager.

Everything works as expected:

  • Firebase Cloud Messaging is correctly integrated (valid google-services.json)
  • Notifications are received while the app is in the foreground using FirebaseMessaging.onMessage
  • On iOS, push notifications work perfectly (foreground, background, and lock screen)

Problem: On Android, I don’t see any notification in the system tray when the app is in the background or terminated.

Tests and observations:

  • Notifications are enabled at the Android OS level
  • The FCM token is correctly received and stored in the server (notificationToken is present in user attributes)
  • The Traccar server sends push messages (confirmed working in foreground)
  • On Android emulator, the notification does appear in the tray, but on real devices, it doesn’t show up unless the app is open

Technical analysis

From what I see in the current Flutter codebase:

  • There is no FirebaseMessaging.onBackgroundMessage handler registered
  • There is no use of flutter_local_notifications to manually show native Android notifications for data-only messages
  • I believe Traccar sends data-only payloads, so on Android, unless manually handled, they won’t appear in the system notification tray

Questions

  1. Is this behavior expected for all Flutter-based Traccar clients on Android?
  2. Is there a plan to support onBackgroundMessage with native notification handling out-of-the-box?
  3. Has anyone implemented flutter_local_notifications to handle background messages properly on Android? Is there a community branch or example?
  4. Is this omitted intentionally due to security or architectural reasons?

Thank you in advance for your help !
I'm happy to contribute a proper implementation of onBackgroundMessage with local notifications if needed.


Sébastien

Anton Tananaev9 days ago
  1. Traccar does not send data-only payloads. Not sure where you got this incorrect assumption, but this makes a lot of your comments and questions invalid.
  2. I tested notifications on a real Android device when the app is backgrounded and it's working correctly.
  3. We don't need to implement onBackgroundMessage because we don't need to do anything special when we receive notifications. Firebase will display them automatically.
  4. You also don't need flutter_local_notifications for the same reason.
  5. I also see you mentioned "terminated" app. In case you're not aware, if you really explicitly stop the app from apps settings, Android will restrict notifications for the app. For if that's the use case you're testing, that's expected. Note that terminating app is not the same thing as swiping it away in recents.