Hi!
I've received java.lang.ClassCastException error in my app before FirebaseMessaging Service_Start sub is triggered.
Every time the app receives a Firebase message the above error will appear then only the Service_Start sub is triggered.
Does anyone experience the same problem? The app can still run after the above error appeared.
I used the same code for my other app without B4XPages and it works just fine. For this particular app I'm using B4XPages and when the message arrived I trigger Main activity to open.
I've received java.lang.ClassCastException error in my app before FirebaseMessaging Service_Start sub is triggered.
Every time the app receives a Firebase message the above error will appear then only the Service_Start sub is triggered.
Does anyone experience the same problem? The app can still run after the above error appeared.
I used the same code for my other app without B4XPages and it works just fine. For this particular app I'm using B4XPages and when the message arrived I trigger Main activity to open.
my FirebaseMessaging code:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
Private smiley As Bitmap
Public message_received As Boolean
End Sub
Sub Service_Create
Try
fm.Initialize("fm")
smiley = LoadBitmapResize(File.DirAssets, "icon.png", 24dip, 24dip, False)
Catch
'ToastMessageShow(LastException.Message,True)
Log("FirebaseMessaging>Service_Create: " & LastException.Message)
End Try
End Sub
Public Sub SubscribeToTopics
Try
fm.SubscribeToTopic("general")
fm.SubscribeToTopic("orders")
Catch
'ToastMessageShow(LastException.Message,True)
Log("FirebaseMessaging>SubscribeToTopics: " & LastException.Message)
End Try
End Sub
Sub Service_Start (StartingIntent As Intent)
Try
If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
Sleep(0)
Service.StopAutomaticForeground 'remove if not using B4A v8+.
Catch
'ToastMessageShow(LastException.Message,True)
Log("FirebaseMessaging>Service_Start: " & LastException.Message)
End Try
End Sub
Sub OrderNotification(title As String, body As String)
Try
'parse body
'format: app-code||recipient||order_id||details
Dim body_array() As String
body_array=Regex.Split("\|\|",body)
'only proceed if message is directed to current app & user
If body_array(0).ToUpperCase = "BAZAARNEGARA-BRAND" And body_array(1) = Main.gUser Then
Dim n As NB6
Config.GetSound
Dim rp As FileProvider
rp.Initialize
Dim folder As String = rp.SharedFolder
Dim FileName As String = Main.gSoundName
'copy the file to the shared folder
If File.Exists(folder, FileName) = False Then File.Copy(File.DirAssets, FileName, folder, FileName)
n.Initialize("custom sound", Application.LabelName, "HIGH").SmallIcon(smiley)
Dim cs As CSBuilder
n.BadgeIconType("LARGE")
n.LargeIcon(smiley)
n.BigTextStyle(title, cs.Initialize.Color(Colors.Red).Append("Tempahan Baru").PopAll, body_array(3))
'disable the default sound
n.SetDefaults(False, True, True)
'set custom sound
n.CustomSound(rp.GetFileUri(FileName))
n.Build(title, "Buka untuk melihat keterangan...", "Main", Main).Notify(1)
End If
Catch
'ToastMessageShow(LastException.Message,True)
Log("FirebaseMessaging>OrderNotification: " & LastException.Message)
End Try
End Sub
Sub SiteNotification(title As String, body As String)
Try
Dim n As NB6
n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley)
Dim cs As CSBuilder
n.BadgeIconType("LARGE")
n.LargeIcon(smiley)
n.BigTextStyle(title, cs.Initialize.Color(Colors.Red).Append("Pengumuman").PopAll, body)
n.Build(title, "Buka untuk melihat mesej...", "Main", Main).Notify(2)
Catch
'ToastMessageShow(LastException.Message,True)
Log("FirebaseMessaging>SiteNotification: " & LastException.Message)
End Try
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
Try
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
message_received = True
Dim title As String = Message.GetData.Get("title")
If title.ToLowerCase.Contains("makluman") Then
SiteNotification(title, Message.GetData.Get("body"))
Else
OrderNotification(title, Message.GetData.Get("body"))
End If
Catch
'ToastMessageShow(LastException.Message,True)
Log("FirebaseMessaging>fm_MessageArrived: " & LastException.Message)
End Try
End Sub
Sub Service_Destroy
End Sub