Android Question Firebase Notifications - Delay and Service Problem

Flosch

Member
Licensed User
Longtime User
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)
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:
 
Last edited:

Flosch

Member
Licensed User
Longtime User
1. Never set StartAtBoot: True on the starter service. Bad things will happen.
Good to know. I will change this.
But will I receive messages after a reboot or did I have to start the APP first.
2. Not critical but better to use NB6 library.

Changed 1 and 2 - Didn't solve the problem

Are you sending the messages with the B4J code?
Yes and no. Normaly with an ESP32 for testing I did it with the B4J Code.
 
Last edited:
Upvote 0

Flosch

Member
Licensed User
Longtime User
App was running.
Two Messages was sent.
Title was not shown
In Body was Shown NULL and the Time (Date)
If I close the App I will receive a message showing the Title and the Body - but not the Date.

Here ist the log:
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
sending message to waiting queue of uninitialized activity (subscribetotopics)
*** Receiver (firebasemessaging) Receive (first time) ***
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
*** Receiver (firebasemessaging) Receive ***
Message arrived
Message data: {}
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
*** Receiver (firebasemessaging) Receive ***
Message arrived
Message data: {}
** Activity (main) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
** Service (httputils2service) Destroy **
 
Upvote 0

Flosch

Member
Licensed User
Longtime User
I downloaded the B4J Programm again and sent the message - same result.
I build a ESP32 dummy - same result.
I tried to use HTTPv1 Methode - same result.

I receive the message empty if the programm is running if it's closed I will receive the notification (old one) with title and body, changes doesn't effect the notification when the programm is closed.

If I change the message (title and body) in one of the Sender (ESP or B4J) I will the notification will only show the title and the body if the program is closed.

It looks like a service is still running which catches the messages.
As I mentioned before in the app settings it also shows me two different notifications under "Settings->Notification".
One notifications with the name of the APP and one Miscellaneous - is this normal?
 
Upvote 0
Top