Android Question Firebase Push Notifications not received until uninstall -> reinstall app

hazaal

Member
Licensed User
Longtime User
Hi,

I just implemented [B4X] Firebase Push Notifications 2023+ last week, and it’s usually working nicely. I haven’t published these new features yet, but during development, it has now happened twice that push notifications suddenly stop being received, and I cannot figure out why. Nothing helps, not even the example project (PushClient in the link above) works. Until I uninstall my app. After reinstalling, without any changes to code, push notifications are received again perfectly.

In Google's Firebase Cloud Messaging API console I can see that some data is moving, but not been received.

I am using Topics, so it cannot be a Token-related issue.

The code is more or less the same as in the example project.

B4XMainPage:
CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", Array("general", "did" & dID))

FirebaseMessaging:
Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
    If FirstTime Then
        fm.Initialize("fm")
    End If
    fm.HandleIntent(StartingIntent)
End Sub

Public Sub SubscribeToTopics (Topics() As Object)
    Log("SubscribeToTopics...")
    For Each topic As String In Topics   
        fm.SubscribeToTopic(topic)
        Log("Subscribed to: " & topic)
    Next   
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Dim mpn_data As String
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    
    Dim body As String = Message.GetData.Get("body")
    Dim title As String = Message.GetData.Get("title")
    
    If title = "deliveries" Then
        If kuvattavat_toimitukset.IsInitialized = False Then
            kuvattavat_toimitukset.Initialize
            If File.Exists(File.DirInternal, "Deliveries.txt") Then
                kuvattavat_toimitukset = File.ReadMap(File.DirInternal, "Deliveries.txt")
            End If
        End If

        Dim itemStrings() As String = Regex.Split("\|", body)
        For Each itemString As String In itemStrings
            Dim itemData() As String = Regex.Split(",", itemString)
            Dim key As String = itemData(0)
            Dim value As String = itemData(1) & "," & itemData(2)
            kuvattavat_toimitukset.Put(key, value)
        Next   

        File.WriteMap(File.DirInternal, "Deliveries.txt",kuvattavat_toimitukset)
    Else   
        Dim n2 As Notification
        n2.Initialize2(n2.IMPORTANCE_HIGH)
        n2.Icon = "icon"
        n2.SetInfo(title, body, Main)
        n2.Notify(1)
    End If
End Sub


FCMPush in B4J is the very same as in Erel's b4j-sendingtool-zip, I can post is if you wish, but there is not much (new) code to see...
 

asales

Expert
Licensed User
Longtime User
Which device and Android version?
I have a similar problem with Redmi 9A (Android 10) and the emulator (14), but the notifications works in a Samsung A71 (13) and Redmi 8A (10).
 
Upvote 0

hazaal

Member
Licensed User
Longtime User
Thanks, but yes, all of those have been done.

I think I’ll try with a "better" phone, but I guess it’s not a real fix—we have over 50 inexpensive phones being used as PDAs, plus some actual PDA devices, and I’m not willing to replace those A14s with devices costing 500-700€.
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
Thanks, but yes, all of those have been done.

I think I’ll try with a "better" phone, but I guess it’s not a real fix—we have over 50 inexpensive phones being used as PDAs, plus some actual PDA devices, and I’m not willing to replace those A14s with devices costing 500-700€.
I had the same problem, happens only in Android with topics in my case. My deivce was an Redmi Note 13, which is not an "old" phone I think

 
Upvote 0
Top