Android Question (solved) fm_MessageArrived not fired when APP is in background mode

Fabio Campanella

Member
Licensed User
Longtime User
Hello everybody, although I have read many threads on the subject, I did not understand what I have to do to be able to open the APP when I tap the push message.

These are the libraries I use:
    #AdditionalJar: android-pdf-viewer.aar
    #AdditionalJar: com.android.support:support-v4
    #AdditionalJar: Pdfium.aar
    
    #AdditionalJar: androidx.biometric:biometric
    '#Extends: android.support.v7.app.AppCompatActivity
    #AdditionalJar: androidx.arch.core:core-runtime
    #AdditionalJar: androidx.appcompat:appcompat
    #Extends: android.support.v4.app.FragmentActivity

This is my firebase service:
#Region  Service Attributes
    #StartAtBoot: false   
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public fm As FirebaseMessaging
    Public Token As String
    
End Sub

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

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("suitenextappflow") 'you can subscribe to more topics
    Token = fm.Token
    Log("Il Token è = " & Token)
End Sub

public Sub fm_TokenRefresh
    Token = fm.Token
    Log("Il Token è = " & Token)
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    
    Log($"Message data: ${Message.GetData}"$)
    
End Sub


public  Sub SendNotification(title As String, content As String, tag As String)
    
    Dim nb As NotificationBuilder
    nb.initialize
    nb.SmallIcon="icon"
    nb.ContentTitle= title
    nb.ContentText=content
    nb.DefaultLight=True
    nb.DefaultSound=True
    nb.DefaultVibrate=True
    nb.ContentInfo=""
    nb.subtext=""
    nb.Priority= 10
    If tag <> "" Then
        nb.Tag = tag
    End If
    nb.setActivity(Main)
    nb.Notify(1)
    
End Sub

Sub Service_Start (StartingIntent As Intent)   
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.   
End Sub

Sub Service_Destroy
    
End Sub

fm_MessageArrived is only called when the APP is in foreground mode. I have other APPs that use the same service and the APP is opened, why not on this one in particular? Could it be due to this (I introduced them to use biometric)?

B4X:
#AdditionalJar: androidx.biometric:biometric
    '#Extends: android.support.v7.app.AppCompatActivity
    #AdditionalJar: androidx.arch.core:core-runtime
    #AdditionalJar: androidx.appcompat:appcompat
    #Extends: android.support.v4.app.FragmentActivity

Thanks in advance for your attention ... please help me, I've been losing my mind for days :(
 

Fabio Campanella

Member
Licensed User
Longtime User
Are you using the B4J code to send the messages?

I Erel,
no, I use my code wrote in C# that work with all APPs that I've developed. If send message from Firebase Console, I have same behaviour (fired when in foreground, not fired in background)
 
Upvote 0

Fabio Campanella

Member
Licensed User
Longtime User
Excuse me Erel,
I use my own system integrated in a large software for the professionals of a large company. This program developed in .NET Core sends push messages through a code that has worked for over 10 years with B4A, in fact it works with all the APPs previously developed except this one. I am unable to use B4J to send push messages to the APP also because there is a whole integrated system that keeps the token for users and sends messages to all the devices associated with it. Again, the system has always worked.
 
Upvote 0

Fabio Campanella

Member
Licensed User
Longtime User
I've tried to use B4J client to send message; effectively work correctly.
I noticed that for android messages the notification section is omitted (as managed by the b4J client) ... behavior a little different from what Firebase declares in its documentation but that's okay ... I send for the android only the data part and then I do a sendnotification in the fm_MessageArrived setting as activity the one to open at the touch of the push message ... all ok ... solved .. thanks to all.
 
Upvote 0
Top