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

Status
Not open for further replies.

Smee

Well-Known Member
Licensed User
Longtime User
Can you post a link to the code?

What is the problem? It is very simple to implement this solution and handle the message.
Can you post a link to the code?

What is the problem? It is very simple to implement this solution and handle the message.
Sorry Erel I did not make myself clear,

I am shortly going to be renewing my sub. I was looking at the Firebase messaging and because I am not able to write and test yet I was wondering what the difference was between the Java snippet for receiving messages and the same code written in B4A. It looks the same to me
Cheers
 

Smee

Well-Known Member
Licensed User
Longtime User
Sorry yes I meant the B4J and Thanks I thought it did not look any different from B4A
 

Mahesh Ramnathan

Member
Licensed User
Hi Erel,
I got following error while trying to implement FCM (Firebase Notification) as per the instruction given above.

Error :
B4A version: 6.31
Parsing code. (0.17s)
Compiling code. (0.33s)
Compiling layouts code. (0.01s)
Organizing libraries. Error
Maven artifact not found: com.google.firebase/firebase-messaging

I have installed following latest version
- Android Support Repository - 47
- Google Repository - 8
- Google Play Service -39

Also installed fresh Android-sdk on D Drive after un-installed from C Drive.

 

Attachments

  • upload_2017-5-5_18-24-24.png
    15.5 KB · Views: 262

Mahesh Ramnathan

Member
Licensed User
Can you guide us how we can test firebase notificaiton ? How we can send scheduled push notification through dot net application ?
Incidentally, we are switching from a working setup of GCM+B4X over to Firebase
 
Last edited:

Ohanian

Active Member
Licensed User
Longtime User
Can you guide us how we can test firebase notificaiton ? How we can send scheduled push notification through dot net application ?
Incidentally, we are switching from a working setup of GCM+B4X over to Firebase

Hi,

Here's a sample vb.net code :

B4X:
Imports System.Net.Http
Imports System.Web.Script.Serialization
Imports Newtonsoft.Json
Imports System.Net.Http.Headers
Imports System.Text
Imports System.ComponentModel


Sub SendPush

   Dim sKey As String = String.Empty
   sKey = "YOUR_KEY"

   Dim HTTPClient As New HttpClient

    Const QUOTE = """"

    Dim sTopic As String = String.Empty

    Dim js As New JavaScriptSerializer()
    Dim Data As String = ""

Data = "{'priority':'high', 'to':'\/topics\/$TOPIC$','data':{'title':'$TITLE$','body':'$BODY$','id':'$ID$'}}".Replace("$TOPIC$", sTopic).Replace("$TITLE$", txtTitle.Text).Replace("$BODY$", txtBody.Text).Replace("$ID$", txtID.Value)

     Data = Data.Replace("'", QUOTE)

     Dim Request As New HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send")
     Request.Content = New StringContent(Data, System.Text.Encoding.UTF8, "application/json")

    HTTPClient.BaseAddress = New Uri("https://fcm.googleapis.com/fcm/send")
    HTTPClient.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("key", "=" & sKey)

    Dim result = HTTPClient.SendAsync(Request).Result
    Dim oResult = result.Content.ReadAsStringAsync
    If oResult.Result.Contains("message_id") Then
            MessageBox.Show("Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Else
           MessageBox.Show(oResult.Result, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If
    
end sub

BUT It’s not reliable (I don’t know why), use B4J code to send push.
 

biometrics

Active Member
Licensed User
Longtime User
I have a B4A and B4i app that needs notifications but it will be sent from a website running PHP.

Does anyone have PHP code to share to demonstrate how to send a notification to Firebase?

Also is Firebase the easiest way to send notifcations?
 

luke2012

Well-Known Member
Licensed User
Longtime User
It is possible to configure an App (for FCM test purpose only) without publish it on the Play Store?

I mean that the app will be installed on a Android (internet connected) device and registered within firebase console only ?
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi all,
How to implement / call the "SendMessage" code within a UI (desktop) B4J Application ?
 
Last edited:

An Schi

Well-Known Member
Licensed User
I just made two EditText for title and body and a button. In the button_click i pasted the send code given here and adjusted it to my keys. That's it...
Oh and don't forget to check the needed libraries.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…