Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ID ${Message.MessageId}, Data ${Message.GetData}"$)
Dim mapParameters As Map : mapParameters.Initialize
If Message.GetData.ContainsKey("promo") Then
mapParameters.Put("promourl",Message.GetData.Get("promo"))
mapParameters.Put("Title", Message.GetData.Get("title"))
mapParameters.Put("Body", Message.GetData.Get("body"))
End If
If Message.GetData.ContainsKey("OfferID") Then
mapParameters.Put("OfferID", Message.GetData.Get("OfferID"))
End If
Dim jgen As JSONGenerator
jgen.Initialize(mapParameters)
Dim n As NB6
n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True)
If Message.GetData.ContainsKey("imgbig") Then
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Message.GetData.Get("imgbig"))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim img_big As Bitmap
img_big = j.GetBitmap
n.LargeIcon(img_big)
End If
j.Release
End If
If Message.GetData.ContainsKey("imgsmall") Then
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Message.GetData.Get("imgsmall"))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim img_small As Bitmap
img_small = j.GetBitmap
n.SmallIcon(img_small)
End If
j.Release
Else
Dim smallbmp As Bitmap
smallbmp.Initialize(File.DirAssets,"firebase24.png")
n.SmallIcon(smallbmp)
End If
If mapParameters.ContainsKey("OfferID") Then
n.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString, Main).Notify(4)
Else If mapParameters.ContainsKey("promourl") Then
n.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString, promo).Notify(4) ' The promo url is opened on another activity.
Else
n.Build(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString, Main).Notify(4)
End If
End Sub