Android Question A problem with firebase notifications

BerlinCoder

Member
Licensed User
Hi,
I have a problem with calling a function after receiving a push notification in my App. In fact, when the screen of the device is off, the firebase service in my app does not run!
For example, when the phone screen is off and the app gets a message, the function of StaticMethods.Read_Notification_Info does not run!



B4X:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")
    Log(fm.Token)
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic(StaticMethods.FCM_APP_TOPIC)
End Sub

Sub Service_Start (StartingIntent As Intent)
    If fm.HandleIntent(StartingIntent) Then Return
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log(Message.GetData.Get("body"))   
    StaticMethods.Read_Notification_Info(Message.GetData.Get("body"))

    
End Sub

Sub fm_TokenRefresh (Token As String)
    Log("Token is " & Token)
End Sub

Sub Service_Destroy

End Sub
 

Alexander Stolte

Expert
Licensed User
Longtime User
How do you send this message? via Firebase console or via smartphone or via B4J?

and for a better functionality I recommend to set the "Start at Boot" to True, then the Service is run everytime and receive ever notifications.

EDIT: you even have to set it to True, otherwise the service will not work if you have the app in the background
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
and for a better functionality I recommend to set the "Start at Boot" to True, then the Service is run everytime and receive ever notifications.

EDIT: you even have to set it to True, otherwise the service will not work if you have the app in the background
This is not correct and not required.

Are you sending the message with the B4J code?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top