Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private FM As FirebaseMessaging
End Sub
Sub Service_Create
FM.Initialize("FM")
End Sub
Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized Then FM.HandleIntent(StartingIntent)
Sleep(0)
Service.StopAutomaticForeground 'remove if not using B4A v8+. Call this when the background task completes (if there is one)
End Sub
Public Sub SubscribeToTopics
FM.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub
Sub FM_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
Dim NB As NB6
NB.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(Application.Icon)
NB.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), "Notification Tag", Main).Notify(1) 'It will be Main (or any other activity) instead of Me if called from a service.
NB.OnlyAlertOnce(True)
End Sub