I have programmed a Firebase Notification App as described in the example. Only the Notifer I replaced with the NB6 Class and set StartAtBoot to True. Everything works fine so far and the app did exactly what I expected. However, after a while I noticed that my messages arrived with a few minutes delay when the phone was in stand-by mode. That's why I wanted to try KMatle's tip (link below), set the priority to HIGH and add a date.
Now I have found the following problem:
When the program is running and I receive a Firebase PN, the content of Message.GetData.Get("title") and Message.GetData.Get("body") is "NULL". So I only get an "empty" notification that only contains the date.
If the app is closed, I get a notification that contains the title and the body, but not the date. Any change to the notification will only affect the notification that is displayed when the program is running.
I also updated the app to use a receiver module instead of a service. But this has the same effect.
Could it be that a service is still running on the phone that intercepts my messages and displays them differently?
If so how can I delete the service from my phone?
I have already uninstalled the app and restarted the phone etc. But nothing has solved the problem.
In the app settings it also shows me two different notifications under "Settings->Notification". Once notifications with the name of the APP and once Miscellaneous. When I turn off the Miscellaneous permission, no more notifications are shown to me when the app is closed.
If I turn off notifications for the app (APP-Name), I no longer receive notifications when the app is in view.
Here is my code: (Receiver-Module)
Starter:
Thanks for your help in advance.
KMatle's tip:
www.b4x.com
Now I have found the following problem:
When the program is running and I receive a Firebase PN, the content of Message.GetData.Get("title") and Message.GetData.Get("body") is "NULL". So I only get an "empty" notification that only contains the date.
If the app is closed, I get a notification that contains the title and the body, but not the date. Any change to the notification will only affect the notification that is displayed when the program is running.
I also updated the app to use a receiver module instead of a service. But this has the same effect.
Could it be that a service is still running on the phone that intercepts my messages and displays them differently?
If so how can I delete the service from my phone?
I have already uninstalled the app and restarted the phone etc. But nothing has solved the problem.
In the app settings it also shows me two different notifications under "Settings->Notification". Once notifications with the name of the APP and once Miscellaneous. When I turn off the Miscellaneous permission, no more notifications are shown to me when the app is closed.
If I turn off notifications for the app (APP-Name), I no longer receive notifications when the app is in view.
Here is my code: (Receiver-Module)
FirebaseMessaging:
Sub Process_Globals
Private FM As FirebaseMessaging
Private pws As PhoneWakeState
End Sub
'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
If FirstTime Then
FM.Initialize("fm1")
End If
FM.HandleIntent(StartingIntent)
End Sub
Public Sub SubscribeToTopics
FM.SubscribeToTopic("general")
End Sub
Sub fm1_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData}"$)
pws.PartialLock
Dim n As NB6
n.Initialize("Knock", Application.LabelName, "HIGH")
n.SmallIcon(LoadBitmapResize(File.DirAssets, "knock.png", 24dip, 24dip, False))
n.Visibility("PUBLIC")
n.ShowWhen(DateTime.Now)
n.Build(Message.GetData.Get("title"), Message.GetData.Get("body") & " " & DateTime.Time(DateTime.Now), "tag", Me).Notify(9)
pws.ReleasePartialLock
CallSub(Main, "RefreshData")
End Sub
Sub fm_TokenRefresh (Token As String)
Log("TokenRefresh: " & Token)
End Sub
Starter:
Starter:
#Region Service Attributes
#StartAtBoot: True
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules
End Sub
Sub Service_Create
CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
Thanks for your help in advance.
KMatle's tip:
FCM messages/notifications: Use Phonewakestate to throw notifications without delay
I mentioned that my fcm messages arrive without delay (data messages), but throwing a notification (even with high priority) doesn't work all the time when the phone sleeps. Setting the phonewakestate before throwing the notification and releasing it after seems to work: pws.PartialLock...
Last edited: