Android Question [SOLVED] Error receiving firebase notification

Discussion in 'Android Questions' started by EdisonMales, Jan 11, 2019.

  1. EdisonMales

    EdisonMales Member Licensed User

    I sent a notification from the firebase console if the application is closed there is no error but when the application is open I have the following error .
    what should I do?

    this is the code, guided in this tutorial -> https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/

    Code:
    #Region  Service Attributes
        
    #StartAtBoot: False
       
    #End Region

    Sub Process_Globals
        
    Private fm As FirebaseMessaging
       
    End Sub

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

    Public Sub SubscribeToTopics
        fm.SubscribeToTopic(
    "general"'you can subscribe to more topics
    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 fm_MessageArrived (Message As RemoteMessage)
        
    Log("Message arrived")
        
    Log($"Message data: ${Message.GetData}"$)
       
        
    Dim n As Notification
        n.Initialize
        n.Icon = 
    "icon"
        n.SetInfo(Message.GetData.Get(
    "title"), Message.GetData.Get("body"), Menu)
        n.AutoCancel=
    True
        n.Notify(
    1)
       
    End Sub

    Sub Service_Destroy

    End Sub
     
  2. José J. Aguilar

    José J. Aguilar Active Member Licensed User

    Not sure if can be your problem, but I’ve read some place “SetInfo” must be the last command before call the notificatin.
    Try to move it down “Autocancel”
     
    EdisonMales and mangojack like this.
  3. DonManfred

    DonManfred Expert Licensed User

    Here the problem starts.
    Send the Notifiction with the B4J App

    There is no data. Even if you use the Notication right (see answer from @José J. Aguilar too) it will be empty as there is no text and body inside the Message arrived.
     
    José J. Aguilar likes this.
  4. EdisonMales

    EdisonMales Member Licensed User

    thank you friend, the problem was solved
     
    Last edited: Jan 14, 2019
  5. EdisonMales

    EdisonMales Member Licensed User

    No matter where you send the notification, I always have the same error.
     
  6. DonManfred

    DonManfred Expert Licensed User

    If the error is still the same then you did not fixed the issue!

    Based on the error you are using the Notification object wrong.

    Post your updated fm_MessageArrived sub.
     
    Last edited: Jan 13, 2019
  7. EdisonMales

    EdisonMales Member Licensed User

    the problem is solved when “SetInfo” to move it down “Auto Cancel”

    Code:
    #Region  Service Attributes
        
    #StartAtBoot: False
        
    #End Region

    Sub Process_Globals
        
    Private fm As FirebaseMessaging
        
    End Sub

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

    Public Sub SubscribeToTopics
        fm.SubscribeToTopic(
    "general"'you can subscribe to more topics
    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 fm_MessageArrived (Message As RemoteMessage)
        
    Log("Message arrived")
        
    Log($"Message data: ${Message.GetData}"$)
        
        
    Dim n As Notification
        n.Initialize
        n.Icon = 
    "icon"
    '    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Menu)
        n.AutoCancel=True
        n.SetInfo(Message.GetData.Get(
    "title"), Message.GetData.Get("body"), Menu)
        n.Notify(
    1)
        
    End Sub

    Sub Service_Destroy

    End Sub
    but when the app is open the notification does not arrive, the null message arrives, what could it do?

     
  8. DonManfred

    DonManfred Expert Licensed User

    New issue -> Create a new thread posting all relevant info. Message data: {} means the pushnotification you got does not contain the relevant data. Send the Notification with the B4J App and NOT with the console
     
  9. Andrew (Digitwell)

    Andrew (Digitwell) Active Member Licensed User

    It is possible to use the Firebase console.
    It seems that B4X only picks up the custom data fields, so you need to place your data there.
    the standard fields are ignored.
    Using the B4J tool is much simpler.

    Don't forget to set the topic also.

    upload_2019-1-14_17-3-14.png
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice