Android Question Firebase Push Notifications 2023+ works with IOS but not Android

Kevin Hartin

Active Member
Licensed User
I note that there was an unanswered post about this very same question back in August.

I have both the PaushExample and my own App working fine in B4i, but both resuse to receive any messages in B4a.

It has the correct json file, as it wouldnt compile until i setup on the firebase site and downloaded. It seems to subscribe correctly, but when I send using the B4j app, I receive on the iPhone, but not the Android
B4X:
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)
    For Each topic As String In Topics
        fm.SubscribeToTopic(topic)
        Log("SUBSCRIBED: "&topic)
    Next
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    If B4XPages.IsInitialized And B4XPages.GetManager.IsForeground Then
        Log("App is in the foreground. In iOS a notification will not appear while the app is in the foreground (unless UserNotificationCenter is used).")
    End If
    Dim n2 As Notification
    n2.Initialize2(n2.IMPORTANCE_HIGH)
    n2.Icon = "icon"
    n2.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n2.Notify(1)
End Sub

Sub fm_TokenRefresh (Token As String)
    Log("TokenRefresh: " & Token)
End Sub

Previously (more than a year ago) I had the old messaging working fine on a number of Android apps, but did have some difficulties with IOS.

Any help is much appreciated.

Kev
 
Last edited:

Kevin Hartin

Active Member
Licensed User
The code is for B4i

Where is your B4A Code? This is the B4A Forum
Oops, to many windows open...

B4X:
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)
    For Each topic As String In Topics
        fm.SubscribeToTopic(topic)
        Log("SUBSCRIBED: "&topic)
    Next
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    If B4XPages.IsInitialized And B4XPages.GetManager.IsForeground Then
        Log("App is in the foreground. In iOS a notification will not appear while the app is in the foreground (unless UserNotificationCenter is used).")
    End If
    Dim n2 As Notification
    n2.Initialize2(n2.IMPORTANCE_HIGH)
    n2.Icon = "icon"
    n2.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n2.Notify(1)
End Sub

Sub fm_TokenRefresh (Token As String)
    Log("TokenRefresh: " & Token)
End Sub
 
Upvote 0

Kevin Hartin

Active Member
Licensed User
The code here looks correct. Start with the example project: https://www.b4x.com/android/forum/threads/b4x-firebase-push-notifications-2023.148715/
You are probably missing something.

Once you get it working you can continue with your project.
That is the PushExample. I reverted to that after experiencing the difficulties in my app, but I experience the very same behavior. B4i works B4a does all the right things but does not receive anything.

Is it the B4a apps json that is the key to subscribing and subsequently receiving? My first compile had the demo json with the new app string com.motosamoa.pushtest and failed on compile but was fine once I downloaded the json.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…