Sub Process_Globals
Private fm As FirebaseMessaging
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Public Sub SubscribeToTopics
If fm.IsInitialized Then
fm.SubscribeToTopic(public_data.topic) 'you can subscribe to more topics
public_data.firebase_token = fm.Token
LogColor(fm.Token,Colors.Red)
Else
fm.Initialize("fm")
fm.SubscribeToTopic(public_data.topic) 'you can subscribe to more topics
public_data.firebase_token = fm.Token
LogColor(fm.Token,Colors.Red)
End If
LogColor(fm.Token,Colors.Red)
End Sub
Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
Sleep(0)
LogColor("Firebase Topic ->"& public_data.topic,Colors.Red)
Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
Log(Message.GetData.Size)
If Message.GetData.Size > 0 Then
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
n.Notify(1)
CallSubDelayed3(chat_form,"received_data",Message.GetData.Get("title"),Message.GetData.Get("body"))
Else
CallSubDelayed3(chat_form,"received_data","Invalid message","Invalid Message")
End If
End Sub
Sub Service_Destroy
End Sub