When the device screen is on, the MessageArrived event is firing and the associated code running correctly.
However when the device screen is off, the device receives a notification sound and icon, but the MessageArrived event is not firing.
My manifest is targeting the following --
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="26"/>
isn´t it the messagearrived sub which creates the Notification? So; if you get a notification then the sub must be run as it is this sub who created the notification.
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
n.Notify(1)
End Sub
No, the FCM message contains both a data string and a notification object. I can tell from adding of log statements that the event is not firing when the device screen is off.
Works perfectly when the screen is on.
Where does the notification and sound come from if it is not your sub???
Firebase itself does not create a Notification! They just sends the Pushnotification and the rest is in your app.
My issue isn't with the notification, it's with the fact that when the screen is off on the device the Firebase service's MessageArrived event doesn't trigger. However it does when the device's screen is on.
The first line of this event is Log(Message) so I can see it's not firing from the logcat.
See Google's documentation of the different types of messages such as data/foreground/background. FCM handles them different. I always use data messages like you now. Then you have to throw notifications on your own but it's more flexible.