Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Delphi 11 – Firebase Cloud Messaging ( FCM ) – Android Push Notification

Digital solution partner

Delphi 11 – Firebase Cloud Messaging ( FCM ) – Android Push Notification

RAD Studio 11 Alexandria push notification with Android via Firebase.

Targets:

1 – Receive push notifications on my Android app

2 – Have a server system for sending push notifications

 

Assumptions from which I started for this test:

1 – Have a Google Firebase account: https://console.firebase.google.com/

2 – Have an app published on the Google store: https://play.google.com/console/u/0/developers/

3 – Embarcadero documentation available on the wiki page: https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Firebase_Android_Support

 

Goal 1 (Receive push notifications on my Android app)

Create a project on Firebase in which you will associate your apps on the play store.

Once the project has been created, through its settings click on the “Add App” button:

 

 

 

 

 

 

At this point you will get the details of your Firebase associated app:

It is very important that the package name matches the one you entered in the Delphi project options:

 

At this point you have to download the “google-services.json” file and copy it to the project folder.

Also through the Delphi Project Options it is necessary to select the Project -> Option -> Application -> Services item and the target application you want to manage (Release or Debug).

At this point click on the “Import” button and import the “google-services.json” file you downloaded from firebase and you should fill in the values ​​that identify your app on firebase:

Still on Delphi we have to go to Project> Options …> Application> Entitlement List and set “Receive push notifications” to true.

Well now let’s get to the point, in the construction of the main form we have to put the following code to register the application to receive notifications:

And create two methods

At this point, compile the application and run it on your device.

Inside memoLog you will find a JSON containing the deviceID, you have to copy it to test sending the first message from firebase.

et Violà the push message arrives on the application.

 

Goal 2 (Send pushes from your server)

Copy the server key and perform a rest call as follows:

 

The JSON must also contain the “notification” object if you want the notification to arrive even when your app is not active:

 

that’s all