- Home /
Firebase Cloud Messaging notifications
I'm trying to achieve the following behavior for push notifications using Firebase Cloud Messaging for Unity in an Android app.
If app is in foreground, handle directly in app (access key-value pairs in push message). Do not show notification in system tray. (Or possibly show notification in tray but then I must be able to clear it from the app)
If app is in background, show notification in system tray. When user clicks notification or clicks app icon on desktop, bring app to foreground, clear system tray and access key-value pairs in push message.
If app is not running, show notification in system tray. When user clicks notification or starts app from icon, start app, clear system tray and access key-value pairs in push message.
Depending on whether I populate "data" and/or "notification" fields in the push message in the server I can achieve 1,2,3 above in different combinations but I cannot figure out how to achieve all of them.
$$anonymous$$aybe have android activity updated and $$anonymous$$essageForwardingService service added to android manifest as described here https://firebase.google.com/docs/cloud-messaging/unity/client#note_for_android
Sorry, I don't understand. According to my Assets/Plugins/Android$$anonymous$$anifest.xml I am using $$anonymous$$essagingUnityPlayerActivity as my $$anonymous$$AIN LAUNCHER Activity. Also, the manifest contains a $$anonymous$$essageForwardingService.
$$anonymous$$y problem is that if the App is in background or not running, and the user brings the app to foreground by clicking the app icon (not the notification in system tray), the FC$$anonymous$$ notification is not delivered to the App.
Would creating a custom Activity implementing onNewIntent as detailed on the page you linked to really solve this? I would have guesed i would have to somehow check for notifications in OnAwake but I cannot figure out how. (possibly by calling native android classes via AndroidJavaObject but it feels like a hack...)
Answer by AskCarol · Dec 11, 2019 at 03:59 PM
Have you taken a look at the Quick Start sample project for Unity:
Thanks for the tip, I did have a look and I think I'm doing it right. I discovered that when running a development build for Android it seems the app can be active even though the mobilde device has activated the lock screen behind the app and in this state it seems Firebase considers the app to be in the background even though it's active.
After this insight the only thing I'm missing is some way to check if there are any notifications in the system tray when the app is brought to foreground since I would like to process any notifications also if the app is launched from the app icon (if launched from the notification in the system tray I receive the notification).
Hi, did you manage to solve this? When in app is it possible to not display messages in the notification tray? Also, can I choose to not show in the notification tray even if a message was received (probably certain times of the day).