I want to use the push notification service in an application that determines user role from user name.
Depending on the role, only certain notifications should be received. I use the following code in a service:
but the problem is that this service runs before the application determines the role of the user.
How do I set the topic to which the user is subscribed?
if i comment the line fm.SubscribeToTopic("general"), the application is still receiving notifications but these are null.
Thanks for any idea!
Depending on the role, only certain notifications should be received. I use the following code in a service:
B4X:
Sub Process_Globals
Public fm As FirebaseMessaging
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Public Sub SubscribeToTopics
fm.SubscribeToTopic("general")
End Sub
Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
Sleep(0)
Service.StopAutomaticForeground
End Sub
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
but the problem is that this service runs before the application determines the role of the user.
How do I set the topic to which the user is subscribed?
if i comment the line fm.SubscribeToTopic("general"), the application is still receiving notifications but these are null.
Thanks for any idea!