1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

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. aarroyo

    aarroyo Member Licensed User

    I have a problem , after initializing, do not assign me token and returns me the following error:

    Error: Cannot run method from watch expression.
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    This is not an error. It just means that the debugger cannot evaluate the expression.
     
  3. alimanam3386

    alimanam3386 Active Member Licensed User

    Hi

    As far as I understand this library ( FirebaseNotification ) is just for push a notify to users , but how can I send a message to an user ? ( without app_key , because it is secrect key and we can't use it in the source code ( client side ))

    Regards
     
  4. ilan

    ilan Expert Licensed User

    what do you mean with message? SMS?

    when you send the notify its up to you how to show it to the user you can show it as a notification or in another way. (like when user open the app show msgbox)
     
  5. alimanam3386

    alimanam3386 Active Member Licensed User

    Thank you, I want send a pm ( like whatsapp or telegram messangers ) userTouser pm , I know by this library I just can handel and get messages from server app. But how can I send pm without secret key ???
     
  6. ilan

    ilan Expert Licensed User

    yes thats what you can do.

    i dont know if it is possible to send directly a msg to whatsapp or telegram from a third party application.
     
    alimanam3386 likes this.
  7. ilan

    ilan Expert Licensed User

    Mashiane and alimanam3386 like this.
  8. alimanam3386

    alimanam3386 Active Member Licensed User

    Thank you , i dot want send pm to a whatsapp or telegram user ! My question it was about how can I send a pm without secret app key that we use it in server side to push a notify ????

    I think I need to run a XMPP jubber server .
     
  9. DonManfred

    DonManfred Expert Licensed User

    you cant.

    Use a server side man-in-the-middle (php for example). Send a request to your server (php) and the script there will send the Notification. The key is stored savety on your server...
    No need to store the TOKEN in source.
     
    alimanam3386 and ilan like this.
  10. Erel

    Erel Administrator Staff Member Licensed User

    You can easily create a B4J server that receives http requests and send push messages.
     
    alimanam3386 likes this.
  11. alimanam3386

    alimanam3386 Active Member Licensed User

    Thank you Erel

    Do you have any source code about how can we receives http request in B4J ?
     
  12. DonManfred

    DonManfred Expert Licensed User

    The forumsearch IS working... TRY IT
     
    victormedranop and alimanam3386 like this.
  13. sasidhar

    sasidhar Active Member Licensed User

    hi,

    I followed the procedure mentioned for firebug notifications on mobile. when I run Jar file i get error mentioned below. same project in the example i have used. API key changed, compiled the project, FCMPush.jar file created. same using command prompt when i run i get the error. please let me know the issue.

    C:\Softwares\basic4android-Licensed\Projects\Samples\NFC\UltraLightReader\Limousine\Limousine b4x6.0\FCMPush\Objects>java -jar FCMPush.jar
    Picked up _JAVA_OPTIONS: -Xmx1g -Xms1g
    httpjob._postbytes (java line: 215)
    java.lang.NoClassDefFoundError: javafx/application/Platform
    at anywheresoftware.b4j.objects.FxBA.postRunnable(FxBA.java:17)
    at anywheresoftware.b4a.keywords.Common.CallSubDelayed4(Common.java:500)
    at anywheresoftware.b4a.keywords.Common.CallSubDelayed2(Common.java:484)
    at b4j.example.httpjob._postbytes(httpjob.java:215)
    at b4j.example.httpjob._poststring(httpjob.java:261)
    at b4j.example.main._sendmessage(main.java:109)
    at b4j.example.main._appstart(main.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.main(main.java:29)
    Caused by: java.lang.ClassNotFoundException: javafx.application.Platform
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang

    thanks
    sasidhar
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Are you sure that you have used the B4J project as is? Looks like you have created a UI project instead of a non-ui project. Anyway you should use Java 8u40+.

    For further discussion please start a new thread in the B4J questions forum.
     
  15. Anser

    Anser Well-Known Member Licensed User

    While using GCM, in the PushService Service we used to make use of the following event Sub to get the Token ID

    Code:
    Sub HandleRegistrationResult(Intent As Intent)
        
    If Intent.HasExtra("error"Then
            
    Log("Error: " & Intent.GetExtra("error"))
            
    ToastMessageShow("Error: " & Intent.GetExtra("error"), True)
        
    Else If Intent.HasExtra("unregistered"Then
            
    Log("Reached HandleRegistrationResult Unregister")
            
    'Remove GCM ID details from My Table

        
    Else If Intent.HasExtra("registration_id"Then
            
    Log("Reached HandleRegistrationResult registration ID")
            
    Dim rid As String
            rid = 
    Intent.GetExtra("registration_id")
            
    Log("GCM RegID from PushService : " & rid )
            
    'Update My Table with the newly received GCM Registration ID
         
        
    End If
    End Sub
    Here you have mentioned about the FirebaseMessaging.Token, Is there any even to get the TokenID like as shown above in case of Gcm
    OR
    The Token ID is available immediately after Subscribing to a topic
    For eg:
    Code:
    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
       fm.Token 'Will I get the Token ID from here
    End Sub
    Or Should I have some Sub in the FireBaseMessaging Service as follows
    Code:
    Sub fm_TokenRefresh(cTokenID as String)
       
    Log( cTokenID )
    End Sub
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    fm.Token will return the current token. TokenRefresh will fire whenever the token changes.
     
  17. Anser

    Anser Well-Known Member Licensed User

    Thanks for confirming.

    So, incase if the token changes, is that the right way to get the refreshed token ?. I mean the code in FireBaseMessaging Service as posted below
    Code:
    Sub fm_TokenRefresh(cTokenID as String)
       
    Log( cTokenID )
    End Sub
    Do I have to take care of the above in FireBaseMessaging Service ?
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    Yes.

    In most cases no. Use topics to send the messages. The tokens are not required.
     
  19. Anser

    Anser Well-Known Member Licensed User

    I am just converting my existing code that used GCM to FCM

    When we receive Push Messages In GCM, in the Sub MessageArrived (Intent As Intent), we used to check whether a particular property/data was there in the sent message using the following code

    Code:
    Dim cMsg As String
    Dim UseBigPictureStyle As Boolean
    UseBigPictureStyle = 
    False
    If Intent.HasExtra("message"Then cMsg = Intent.GetExtra("message")
    If Intent.HasExtra("UseBigPictureStyle"Then UseBigPictureStyle = True
    How do I execute the same when I receive Message in FCM in the Sub fm_MessageArrived (Message As RemoteMessage)
    The following works well if the received message contains a Key, but fails when the received message does not contain the key. For eg
    Code:
    Dim cMsg As String
    Dim UseBigPictureStyle As Boolean
    UseBigPictureStyle = 
    False
    If Message.GetData.Get("message") <> "" Then cMsg = Message.GetData.Get("message")
    'If  "UseBigPictureStyle" is not included then the code freezes there
    If Message.GetData.Get("UseBigPictureStyle") <> "" Then UseBigPictureStyle = True
    If I include UseBigPictureStyle data in the message that I send, then everything works fine, but if it doesn't contain then the code does not get executed beyond the point
    If Message.GetData.Get("UseBigPictureStyle") <> "" Then UseBigPictureStyle = True


    EDIT : Sorry for the confusion. Forgot that it is a Map, the solution is
    Code:
    If Message.GetData.ContainsKey("UseBigPictureStyle"Then UseBigPictureStyle = True
    Regards

    Anser
     
    Last edited: Jul 2, 2016
    pesquera likes this.
  20. alimanam3386

    alimanam3386 Active Member Licensed User

    Hi

    When I use Web Socket Server(B4J) to send a message with FCM I get an error :

    Code:
    {
      
    "data": {
      
    "receivertoken""",
      
    "pmsenderid""SenderId HERE",
      
    "body""hi my friend !"
      
    },
      "to": "AcQQ4p4WI1g:APA91bGhKhiydgATbIkNgzu5F6WGF5pm_HxLM9lNSA7bHM0dg89sCbpgpEQc3srf4J92oZkyKd3DId5HqroBmWMWkGCVMHYvxOY1nYrcV6GnTJ--x2T61igugVdDwgCM-D-OJPzZThze"
    }

    java.lang.RuntimeException: java.lang.IllegalStateException: Toolkit not initialized
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
       at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
       at anywheresoftware.b4j.object.WebSocketModule$Adapter$1.run(WebSocketModule.java:126)
       at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
       at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
       at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:195)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
       at java.util.concurrent.FutureTask.run(FutureTask.java:266)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at java.lang.Thread.run(Thread.java:745)
    Caused by: java.lang.IllegalStateException: Toolkit not initialized
       at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
       at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
       at javafx.application.Platform.runLater(Platform.java:83)
       at anywheresoftware.b4j.objects.FxBA.postRunnable(FxBA.java:17)
       at anywheresoftware.b4a.keywords.Common.CallSubDelayed4(Common.java:500)
       at anywheresoftware.b4a.keywords.Common.CallSubDelayed2(Common.java:484)
       at b4j.example.httpjob._postbytes(httpjob.java:215)
       at b4j.example.httpjob._poststring(httpjob.java:261)
       at b4j.example.b4a._v6(b4a.java:123)
       at b4j.example.b4a._pm_message(b4a.java:79)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
       at java.lang.reflect.Method.invoke(Method.java:498)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
       ... 10 more
    I attached my source code , how can I solve this error ?
     

    Attached Files:

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