Android Question problem with " CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")"

appie21

Active Member
Licensed User
Longtime User
Hi

I try to follow this tutorial
https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/


Hi in the first post you say

B4X:
'Starter service
Sub Process_Globals

End Sub

Sub Service_Create
   CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub

But FirebaseMessaging is red what do I wrong? It says that itr is not declarared
you also say at

2. Add a Service named FirebaseMessaging to your app (must be this name):

But how to do?


here is my code

Starter
B4X:
Sub Process_Globals
    Public analytics As FirebaseAnalytics
    
   Private fm As FirebaseMessaging
End Sub

Sub Service_Create
   fm.Initialize("fm")
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") ' why is this one red
    
End Sub

Public Sub SubscribeToTopics
   fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
   If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
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

Sub Service_Destroy

End Sub

Main


B4X:
ub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These g
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
lobal variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…