Android Question firebase notification fm_MessageArrived not fired?

Cadenzo

Active Member
Licensed User
Longtime User
If a new message arrived, I want to download some data from the server. this is allwais done, when the App starts. But if it is allready started, I set b_NewMsgArrived = True. Then the server also will be visited.

Code in the FirebaseMessaging:
B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Starter.b_NewMsgArrived = True
    NewMessage(Message.GetData.Get("title"), Message.GetData.Get("body"))
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
End Sub

Code in Main:
B4X:
Sub Activity_Resume
   If Starter.b_NewMsgArrived = True Then GetNews(True)
End Sub
But if the app is in the backround (the phone is turned off), it does not work. I get the notification, that new message is arrived. This means, that fm_MessageArrived is fired, right? But b_NewMsgArrived is never true. It is hard to debug, because the firebase notificatin olny works in release mode. Any suggestions?
 
Last edited:

Cadenzo

Active Member
Licensed User
Longtime User
OK, I found the reason may be here in post #10. When my server sends the pushups only with "data" it works. But than it is not shown as notification in iOS. In iOS I need the "notification" part. I use a own server, that handles all tokens and app-IDs. So the messages from one App to another are sent to an app-id of the reciever. I have apps for android and iOS. Any ideas, how it could work for both? The "notification" part is needed for iOS, but it is also the reason for the bug in post #1.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
So I solved it now on the server itself. The apps now register on the server not only with ID, Pin and Token, but also with its system android/iOS. And depending on that, the server includes the "notification" part in the payload or not.
 
Upvote 0
Top