Android Question Firebase Notification receive case

taylorw

Active Member
Licensed User
Hi all, I usging Firebase for notification.

I have a problem with the notification, when user turn off they phone or no internet but after they connect to network or turn on they phone they no receive the notification.

Is any mistake for me?Please help for this.
 

taylorw

Active Member
Licensed User
This is my code.

B4X:
Private Sub SendMessage(Topic As String, Title As String, Body As String)
    
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & Main.API_KEY)
    
End Sub

B4X:
SendMessage(Notification_Topic, Notification_Title, Notification_Body)

B4X:
Private fm As FirebaseMessaging

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

Public Sub SubscribeToTopics
    
    fm.SubscribeToTopic(Notification_Topic)
    
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
    Notification_Topic.Initialize
    SFC.Initialize

End Sub

Sub fm_MessageArrived (Message As RemoteMessage)

    Dim n As Notification
    n.Initialize
    n.Icon = "icon"

            n.SetInfo2(Message.GetData.Get("title"), Message.GetData.Get("body"), Message.GetData.Get("StartDate"), frmLeave_List)
            
            n.AutoCancel = True
            n.Notify(Notification_Count)
            Notification_Count = Notification_Count +1
    
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top