B4A Library FirebaseNotifications - Push messages / Firebase Cloud Messaging (FCM)

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jun 9, 2016.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    It will use the latest version of Firebase installed. Update Google Repository in Android SDK Manager.
     
  2. panagiotisden2

    panagiotisden2 Active Member Licensed User

    A
    OK erel thank you
     
  3. tznikos

    tznikos Member Licensed User

    Hi,

    I face the same problem with uniplan,

    When the application is in the foreground, i receive the notification push, but the title and body are null.
    If the application is in the Background or is closed then receive the message correct,

    can anyone know why happen that ?
     
    Last edited: Mar 13, 2017
  4. Erel

    Erel Administrator Staff Member Licensed User

    Are you sending the messages with the B4J code?
     
  5. tznikos

    tznikos Member Licensed User

    No, i sending the message from Firebase Console ->Notification ->New message
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    This is the problem. You need to use the B4J code.
     
  7. rad

    rad Member Licensed User

    Hi all...

    I have implement this library with successful, although sending notification from firebase console sometimes getting null value...
    But when I try sending notification from B4A :

    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: Simpush
        
    #VersionCode: 1
        
    #VersionName: Simple
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: portrait
        
    #CanInstallToExternalStorage: False
    #End Region

    #Region  Activity Attributes
        
    #FullScreen: False
        
    #IncludeTitle: 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.
        Private const API_KEY As String = "AIzaSyAQ7XJnHBD1lz2z2rJpGvmKtF4O4Hy9J0Q"
    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.

        
    Private btnPush As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("frmMain")
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Private Sub SendMessage(Topic As String, Title As String, Body As String)
       
    Dim Job As HttpJob
       Job.Initialize(
    "fcm", Me)
       
    Dim m As Map = CreateMap("to"$"/topics/${Topic}"$"priority""high")
       
    Dim data As Map = CreateMap("title": Title, "body": Body)
       m.Put(
    "data", data)
       
    Dim jg As JSONGenerator
       jg.Initialize(m)
       Job.PostString(
    "https://fcm.googleapis.com/fcm/send", jg.ToString)
       Job.GetRequest.SetContentType(
    "application/json;charset=UTF-8")
       Job.GetRequest.SetHeader(
    "Authorization""key=" & API_KEY)
    End Sub


    Sub JobDone(job As HttpJob)
       
    Log(job)
       
    If job.Success Then
         
    Log(job.GetString)
       
    End If
       job.Release
    End Sub

    Sub btnPush_Click
        SendMessage(
    "general""Test""This is only notification test")
    End Sub
    It's nothing happen... no notification arise..
    Can anyone help me to solve this issue?

    I can not use B4J sample because:
    1. I don't have B4J (I only have B4A, and I always develop my application using B4A)
    2. My Current/Existing application which will be add FCM Service are developed from B4A.
     
  8. Alpandino

    Alpandino Member Licensed User

    Hi rad,
    when you send a message from an app you're not sending a notification, but a message that you'll receive inside a specific service called FirebaseMessaging (the name must be this) and in a specific sub called "fm_MessageArrived". In this case it's up to you decide what to do whit this message (do an action, show a notification, modify a db table, etc).
    In your code you're sending a message to the topic called "general", so this message will be received by any device using your app registered to this topic.
    When you send a message from the firebase console, instead, you're sending a notification that will appear on the notification bar only if your app is in background.

    Bye
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Don't use Firebase Console. You are just wasting your time.

    Start with testing your implementation with the B4J code. B4J is free: https://www.b4x.com/b4j.html

    You can later move the code to B4A. It is very very simple.
     
    luke2012 and HAH like this.
  10. rad

    rad Member Licensed User

    Hi Alpandino,
    Thanks for the enlightenment...
     
  11. rad

    rad Member Licensed User

    OK Erel, I will try to install B4J first, and I will report the progress soon...
    Thanks...
     
  12. rad

    rad Member Licensed User

    b4j.jpg

    Hi Erel...

    please explain me, what is wrong with the image above conditions...
    coz I have no idea about java programming... :(
     
    Last edited: Apr 5, 2017
    luke2012 likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this in B4J questions forum.
     
  14. rad

    rad Member Licensed User

    Ok, I will....

    Thanks Erel.
     
  15. Smee

    Smee Well-Known Member Licensed User

    I will soon be renewing my B4A licence but in the meantime I have been the topics on FBM with a view to implementaion into an app I am writing. The java snippet looks exactly like B4A. Why would that code not work within B4A
     
  16. trueboss323

    trueboss323 Active Member Licensed User

    Any information on the battery usage?
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Which code are you asking about?

    None. The process will only start when a message arrives.
     
  18. HAH

    HAH Active Member Licensed User

    how to convert the sending b4j code to b4a MR Erel
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  20. trueboss323

    trueboss323 Active Member Licensed User

    Is there any chance there would be added support for sending messages from the Firebase console?
     
Thread Status:
Not open for further replies.
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